开发者

handling task factory exceptions

开发者 https://www.devze.com 2023-02-26 04:55 出处:网络
I have set up a process to create new tasks to handle file processing. A problem arised where I received and unhandled exception error and just clicking on the continue button, the main process contin

I have set up a process to create new tasks to handle file processing. A problem arised where I received and unhandled exception error and just clicking on the continue button, the main process continued to run. Now I also found that within the child task I was having a file conflict error and as the tasks run as separate .exe i was under the impression that everything would have been thread safe. So for the first issue here is the task creation in the main process..GProcess is a complete project on its own consisting of 6 classes. This is added as a class library reference to the main process class form1

Public Class Form1
 ..Private parser as GProcess.module = new GProcess.module()

dim factory as new taskfactory
factory.startnew(addres开发者_如何学Pythons of parser.main)

try
   task.waitall()
catch ae as aggregateexception
   for each ex in ae.innerexceptions
     logs.insert(ex.message.tostring)
   next
finally
  parser.ctsources.cancel()
end try

now I got the aggregateexception thing from msdn and not sure how to implement it but basically what i want to is cancel the task that caused the exception and contiue running all other tasks and capture the file that the cancelled task was working on and save the name to my logs or if possible restart that task with the file it was working on..

Now for the second issue I have a xmlwriter being created when a class is accessed by the task which should create its own instance of it so not sure why there is a clash but if it does happen, does the task / thread just cancel or does it wait to access the file.

   ....
public class filecleaner

private xmlfile as string = directoryPath & filename
private xwriter as xmltextwriter = new xmltextwriter(xmlfile,nothing)
....


For your second question, the task won't wait for access to the file, it'll throw an exception, that you have to catch, pause, and then try again (up to some count limit, i'd guess) if you want that kind of behavior.

For the first, I'm not sure there's enough to go on here. For instance, Why do you say that "the tasks run as separate .exe"? If you're just spinning up backgroundworker objects, for instance, they don't run as separate "Processes" (ie exe's), they're just threads.

There's nothing in this code that would suggest you're getting seperate processes for your tasks, but, depending on what happens in startne, I suppose it's possible.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号