Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace StackOverflowTest
- {
- class Program
- {
- static bool fault = false;
- static Exception ex;
- static void Main(string[] args)
- {
- Thread t = new Thread(Run);
- t.Start();
- t.Join();
- if(fault)
- {
- Console.WriteLine("fault occured:");
- Console.WriteLine(ex);
- }
- else
- {
- Console.WriteLine("no fault");
- }
- Console.Read();
- }
- static void Run()
- {
- try
- {
- Execute();
- }
- catch(Exception e)
- {
- ex = e;
- fault = true;
- }
- }
- static void Execute()
- {
- WaitOne();
- }
- static bool WaitOne(bool killProcessOnInterrupt = false, bool throwOnInterrupt = false)
- {
- try
- {
- return WaitOne();
- }
- catch(ThreadInterruptedException e)
- {
- /*if(killProcessOnInterrupt)
- {
- Process.Kill();
- }
- if(throwOnInterrupt)
- {
- ExceptionDispatchInfo.Capture(e).Throw(); //this will rethrow the exception with stack trace intact
- throw; //visual studio doesnt know above method will throw, so this has to be here
- }*/
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement