Support > Samples > How to use Coyote Core Framework

How to use Coyote Core Framework

Download source code


The “SampleApplication” application demonstrates the use of the Trace Subsystem.
The SampleApplication Solution includes the following files:
·         MainForm.cs: The Windows Forms class implementing the User Interface.
·         Worker.cs: Division class that lets the user divide two numbers
·         WorkerThread.cs: Thread Class that runs in a separate thread and sends Trace Messages.
·         Program.cs: Windows Forms Application Startup Code and Remoting Config setup. 
The GUI is designed to provide you with three different features:
  1. The “Dividing Tester” lets the user divide two numbers. It deposes an Information Trace Message saying which numbers were divided and Error Trace Messages in case of a “Division by Zero” exception.
  2. The “Stack Walker” demonstrates the use of the TraceAgent.Write method that is able to use the stack frame of another method than that of the caller.
  3. The “Multiple Worker Threads” lets you specify multiple worker threads that give out Trace Messages of the specified type. Choose a Trace Level and a category text and press the “Start” button to spawn a new thread.
The Worker class implements the “Div” method that divides two numbers and uses the TraceAgent’s “Write” method to depose Trace Messages in case of an division by zero exception.
public int Div(int x, int y)
         int retVal = 0;
             //Write some verbose output 
string.Format("Dividing {0}/{1}", x , y ), "Calculation"); retVal = x / y; } catch(System.DivideByZeroException ex) { // Catch the Division by Zero Exception and send a Trace message with // the operators as additional Inforamtion to the Trace output. NameValueCollection col = new NameValueCollection(2); col.Add("param x", x.ToString()); col.Add("param y", y.ToString()); // Send a Trace Message with additonal information. // If we use the Write method overload that takes an Exception object as // parameter the TraceSystem calls the ToString() method on the Exception. TraceAgent.Write( TraceLevel.Error, ex, "ExceptionHandling", col ); } return retVal; }
This class is designed to fire Trace Messages of the desired Trace Level and category within a worker thread. Using the GUI you can spawn multiple worker threads to create heavy load for testing purposes.
public void Run()
    while (true)
          //Write some test messages
string.Format("test message from thread {0}.",
System.Threading.Thread.CurrentThread.ManagedThreadId), Category); //sleep a little while System.Threading.Thread.Sleep(500); } catch (System.Threading.ThreadAbortException ex) { //Just in case we write a message to the trace output TraceAgent.Write(TraceLevel.Warning, ex, "ExceptionHandling"); // and now we have to go away return; } } }