multithreading - How to catch errors from worker threads in console application written in C# -


I currently have a small console application that does a lot of work ( Parallel.ForEach Using) and each of these actions creates sub-threads using ThreadPool.QueueUserWorkItem .

I would like to control an exception by these tasks / threads in the application.

Edit will come around the parallel.forh statement with try..catch : These sub threads emulate users of the system.

Will not work around the statement. You can do something like this:

  public static zero main (string [] args) {string [] files = System.IO.Directory.GetFiles (@ ".", "*. * "); Parallel.ForEach (Files, x = & gt; {{MyAction (x)}} Hold (Exception Pre) {Console.WriteLine (ex.ToString ()}}}}); } Static Zero MyAction (string x) {New Application Exception ("Test:" + x); }    

Comments