Writing USB Drive Portable Applications in C#

One of my favorite things about owning a USB flash storage device is hauling around a bunch of useful tools with me. I'd like to write some tools, and make them work well in this kind of environment. I know C# best, and I'm productive in it, so I could get a windows forms application up in no time that way.

But what considerations should I account for in making a portable app? A few I can think of, but don't know answers to:

1) Language portability - Ok, I know that any machine I use it on will require a .NET runtime be installed. But as I only use a few windows machines regularly, this shouldn't be a problem. I could use another language to code it, but then I lose out on productivity especially in regards to an easy forms designer. Are there any other problems with running a .NET app from a flash drive?

2) Read/Write Cycles - In C#, how do I make sure that my application isn't writing unnecessarily to the drive? Do I always have control of writes, or are there any "hidden writes" that I need to account for?

3) Open question: are there any other issues relating to portable applications I should be aware of, or perhaps suggestions to other languages with good IDEs that would get me a similar level of productivity but better portability?


  • 1) There shouldn't be any problems running a .NET app from a flash drive.
  • 2) You should have control of most writes. Be sure you write to temp or some other location on the hard drive, and not on the flash drive. But write-cycles shouldn't be a problem - even with moderate to heavy usage most flashdrives have a life time of years.
  • 3) Just treat it like's it any app that has xcopy style deployment and try to account for your app gracefully failing if some dependency is not on the box.

  • 如果您想使用com对象,请使用reg-free com并将com对象包含在您的程序中。


    You should always have control of your writes. Applications should be loaded into RAM at startup, and then memory past that is allocated in RAM, so nothing is written to the flash drive.

    The most important thing for a portable application is that basically no installation is necessary for your application. You do not want to be dependant on registry values especially, since your application will not be 'installed' on other computers.

    One of the issues with portable applications you may consider is data persistence. Generally, you write to a user's Application Data folder to save data. If this is the case, any data saved will only apply to the user on that computer. If you want some local application data, you may wish to create a Seralized XML file for your settings and store it locally within your application's directory. This file writing would then likely be the only write actions you'd need to worry about.

    For your .NET portability issue, you could also write a small entry program in C++, which checks if the computer has .NET installed. .NET has registry values you can check to see the versions installed, so if .NET is installed, run your application, else display a message stating that .NET needs to be installed first.

    Edit: I'd like to add that I do application development for Ultrasound machines using XAML in C# 3.0. The application I write works perfectly from a USB Flash Drive, while all user settings are stored on a local AppData basis, so nothing is written to the USB. While the application can be installed through an .exe installer, the installer does not write any registry values the application depends on.

    链接地址: http://www.djcxy.com/p/68184.html

    上一篇: 如何在Swing桌面应用程序中部署JavaFX

    下一篇: 用C#编写USB驱动器便携式应用程序