I have a windows mobile 5.0 application (smartphone) that contains a flat data file (CSV), which contains a header row (two doubles), and a list of entries (two doubles, DateTime, and a string).
Occasionally, I need to "sync" the mobile application with a desktop application. The desktop application should read the CSV from the mobile device, and replace it with a new CSV file, based on the contents of the old one.
This seems pretty easy via RAPI (I'm guessing), but I need to ensure that the mobile application is not running. Is there a way to do this?
Mutex? Remote Process Viewer like stuff? File locking?
Thanks for any help you have
Mike
Just use a simple file locking mechanism for the file being read/updated.
Either rename the file before use or create a second 'lock' file which you can check for the existence of.
For whatever reason, the built-in RAPI Functions don't have anything for checking running processes like the ToolHelp API's. With C you could create a set of custom functions in a device library that call the ToolHelp APIs and in turn are called through CeRapiInvoke (which is a generic catch-all entry point for custom RAPI functions). Unfortunately there's no simple mechanism to do this in managed code.
Just thought of an easy way.
Every 3 seconds the program is running, update a registry key with the current datetime.
When I want to sync, check the mobile registry, check it again 5 seconds later. If the values changed, the program is still running.
Related
My client wanted me to write a simple desktop app such that :
User will select a date. Then the program will travel all files in the windows pc and then create an excel report for all files which are created before the selected date.
Actually it seems really simple application. However, my client told me he has petabytes of data which made me think the app would run for hours even days. I need a really smart solution for that. For instance despite the possibility of a crash or unexpected error etc, I am planning to divide the report into parts and create a new excel file for each 50000 records. In addition, the application should continue from where it left off. In another words, if the application is closed, the application should not start scanning all over again. What is the most logical way for the program to work efficiently and continue from where it left off? What comes to my mind is to put a tick on the folders so that the already looked folders are not looked at again. What is the best way to implement this logic in C#? Is it efficient to create a separate list for the visited folders and then first look if the folder is alreay in list? Which data structures would you use for this problem and how would you implement this?
Thanks.
I want an auto updater that detect modified game files (by comparing files on the client-side and a server) and only download modified files.
The scenario is that there's about one thousand clients in a network, that use same application. If a new version of the application is available, they all have to get the new version.
I see a www.aldera.to game if you install the files their Aelra_patcher application auto patch the files from the server side. It do the exact thing I want:Getting the newest files from server when the patcher is run. But the problem is that clients wrote in C#, and I can't use IcePatch2 inside my application.
So far, the best solution I found is to get .NET Application Updater Component and customize it to fit my needs. But I prefer a solution that dose not require me to maintain another application.
Any idea?
Managing file locks is fairly simple. The process should go something like this:
The game application downloads the installer, if there is any
The game application runs the installer and exits
The installer starts doing the work of updating files as needed. If any files are locked it may wait a short while and try again, or ask the user if it is ok to close the application that have locked the files.
But the topic of minimizing update time and bandwith is a fairly complex. You might want to read Raymon Chens articles on Windows Update Formats to get some appreciation for the various issues.
I'm not familiar with IcePatch2, but it seems to be a fairly generic file synchronization tool. This may be appropriate for your specific use case, but I would expect some use cases to benefit from a more specialized approach. You could for example use knowledge of things like file or resource versions to avoid much of the work a more generic tool has to do.
I'm writing a Windows application in C#.
Its an application that when called outputs data to a printer and com port. It has to be invisible to the user, so I have a separate application to set up the printer and com port parameters that the application reads every time it is started. The application starts, runs for a couple of seconds and then closes, until it is executed again, which will haven periodically every few minutes. So, unless I hard code the printer and com port settings, I guess I need to have them read every time the application is started.
So is it faster to read from, an ini, XML, or registry/local machine?
Speed is my main deciding factor.
Is there any other way to the variables between executions? In Linux i might use environment variables, is that a feasible option in windows?
Thanks
How about using an AppSetting?
This will read an <appsettings> entry that you can put in either the .config for the project or in the machine.config in the Microsoft .NET folder on the machine.
Then in the code You can just reference ConfigurationManager.AppSettings["printer"] anywhere you need to. You can edit the appsetting at any time.
I will warn you though, be very careful when messing with the machine.config, you can really mess up your pc or environment if you use incorrect syntax or forget a closing /> For this reason, I would highly recommend using the .config of your project.
Check this link for more info
There are several threads on SO that describe how to check which application creates a file with tools like Sysinternals process monitor. Is something like this possible programmatically from .net?
Background: My program has to remote-control a proprietary third party application using its automation interface, and one of the functions I need from this application has a bug where it creates a bunch of temporary files in %TEMP% that are called tmpXXXX.tmp (the same as .net's Path.GetTempFileName() does) but does not delete them. This causes the C drive to become full over time, eventually failing the application. I already filed a bug to the manufacturer, but we need a temporary workaround for the time being, so I thought of putting a FileSystemWatcher on %TEMP% that watches tmp*.tmp, collects these files, and after the operation on the third-party application finishes, deletes them. But this is risky as another application might also write files with the same file name pattern to %TEMP% so I only want to delete those created by NastyBuggyThirdPartyApplication.exe.
Is this anyhow possible?
This kind of things is possible, but maybe a bit tricky.
To know who created the file, look at the user that owns it. Therefore you might need to create a specific user, and that application will run under this specific user. In order to do that, you need to create a small application that will start your buggy app by impersonating another user, so anything done within the app will be under this user so as file creating...
I don't know how to monitor and get triggered when a file is created, but nothing can prevent you from setting a timer that wakes up every five or ten minutes, then checks if any file in the directory is owned by the application user and closed, so it deletes it.
Maybe if they react fast for this bug fixing, you won't need your app very long time. So another solution, if possible might just to change the Temp folder into another drive, which has lots of space...
One solution is that you use a FileWatcher to automatically delete all the files but before deleting you should check if the file is not currently locked or used by other process, for example the Sysinternal Suite has a tool called handle.exe that can do this. Use it from the command line:
handle.exe -a
You can invoke this from a c# program (there might be some performance issues though)
So what you would do is when a file is created you verify if it is in use or locked (for example u can use the code provided in Is there a way to check if a file is in use?) and then delete it.
Most of the time when an app is using a temp file it will lock it to prevent just what you fear, that you might delete files from other processes.
As far as I can tell there is no sure way to identify which process created a specific file.
I'm writing an application using windows form and c# 3.0. I was wondering if there is a recommended way of persist data across time. However, i do not want to touch the machine it is running on, as a result, i would like to store the data in the binary executable (preferably, due to the need not clutter up the user's folder with random config files).
So if anyone have any ideas of how to do this, it would be much appreciated!
Jason
If you're looking to store configuration information - app.config or a settings file is probably the way to go.
If you are storing user data - you should really allow the user to control where it is saved - and prefer the \User\Username folder on the machine.
As for what format to store it in ... you can certainly use something like SQLLite - but there's nothing wrong with XML either, if you're not storing true binary data. .NET offers a number of APIs to transform object graphs into XML representations - which you may want to look into.
If you don't want to store anything on the local user's machine, you probably want a network database - or a webservice - to which you upload the users data. Just make sure your users understand this - many don't like their private data being sent somewhere on the web without their consent.
You really don't want to go about modifying the executable file. Many virus scanners quarantine executables that are constantly changing in content or size - as a way to proactively prevent viruses and malware from infecting the machine. You don't want to go there.
Do not modify the executable. Adding a single SQLite database is a much better solution.
Isolated storage is another alternative.
Doesn't clutter install directory
Doesn't cause issues with AnitVirus software
Part of the OS including .Net objects, don't need to install anything else
Already works with the Windows security model
Exists on a per user basis, so saved settings are separated for each user
Can serialize/deserialize obects directly into it
SQLite is what your looking for and is compatible with c#
If you dont want to store data in a SQLite db on the end users PC you could call out to a web service on another server which stores it's data in SQL Server or something else.
I don't believe a windows form project can modify itself like that (I've tried to find a way to do this myself some time ago). Some form of hosted application such as a silverlight application (where the application is essentially a zip file) may be the way to go. Silverlight applications would require the silverlight plugin though (and I'm still not sure if a silverlight application is allowed to modify itself).
I would think that one config file of some sort would be prefereable, and not leave much clutter.
One way to ensure that your applicaiton is entirely self contained would be to use a program like ThinStall after you have compiled the project. This virtualises the application and could give it it's own file system or registry internally to the .exe file.
One way for an executable to change itself would be to put another executable inside it, (embed as a resource then extract it to a file when needed). This executable could then modify the first, however I don't think ther'es any framework for it to do that, so it would require knowing excatly what to change and where.