Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

How Do I Propagate Exception Back to Host Thread?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marc - 17 Aug 2006 22:58 GMT
I'm building a service application that monitors a directory using a
FileSystemWatcher that captures "create" events.  In my "create" event
handler, I do all my custom processing of the new file and then I just need
to delete the file at the end.  Unfortunately, the file has a "write" lock on
it so I can't simply just use File.Delete().  (Oddly, this strange lock does
not exist if I run the program as a console application instead of as a
service, but that's not my primary question.)

To work around this weird behavior, I have opted to spawn a simple
background thread via ThreadPool.QueueUserWorkItem() so that the "create"
event handler can exit and release the lock, and then I can do my file
cleanup operations in the background thread.  This seems to work, but I'm new
to .NET threading.  How do I report an exception in my background thread back
to the host thread in case the delete operation failed?
Alan Pretre - 17 Aug 2006 23:13 GMT
> How do I report an exception in my background thread back
> to the host thread in case the delete operation failed?

What I have done is define and create an "Exception" event and have the
background thread raise it to the main thread.  The payload for the event is
the exception object, IIRC.

-- Alan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.