Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Filesystemwatcher synchronous
Message
 
À
31/08/2009 23:33:38
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Vista
Divers
Thread ID:
01422062
Message ID:
01422152
Vues:
35
>I am creating a PDF programmatically. The ActiveX component basically acts as a printer driver and I can't figure out how to know when it is done so I know the file exists for certain so I can read it into a byte array to store.
>
>I am trying now to do this with system.io.filesystemwatcher but I can't seem to get the syntax right
>

As far as I know, there isn't a nice easy way to only get notified when the file is closed (which is essentially what you want). Instead, I'd wait until the file has been created, then call out to another method which loops until you can get an exclusive lock on the new file (or times out), ex: (sorry, C# code and may not work as-is)
bool IsFileComplete(string fileName, TimeSpan timeout)
{
	bool complete = false;
	DateTime endTime = DateTime.Now.Add(timeout);
	
	while (endTime > DateTime.Now)
	{
		try
		{
			using (FileStream newFile = File.Open(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
			{
				complete = true;
				break;
			}
		}
		catch (IOException) { }		

		System.Threading.Thread.Sleep(100);
	} 
	
	return complete;
}
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform