returning value to main C#
<p>I'll start by saying that i am no beginner in C# but not very much more and need help returning value to main. Or rather tell me what is the "correct" way. </p>

<p>I want to return a fail value (simply -1) from the application, in case of any exception and ending up in a catch. In that case passing info to main to return -1. </p>

<p>The way I solved it was by just adding a static global variable mainReturnValue (to be able to access it from main), and setting its value to -1 in the catches. </p>

<p>Is that a correct way of doing it, based on my current code? </p>

<p>If anyone is wondering the applications is executed without user interaction and that's why I need to catch the exit state. The form/GUI just displays info about the progress, in case it's started manually.  </p>

<pre><code>namespace ApplicationName
{
/// &lt;summary&gt;
/// Summary description for Form1.
/// &lt;/summary&gt;
public class Form1 : System.Windows.Forms.Form
{ ...

static int mainReturnValue = 0; //the return var

static int Main(string[] args) 
{
    Application.Run(new Form1(args));

    return mainReturnValue; //returning 0 or -1 before exit
}

private void Form1_Load(object sender, System.EventArgs e)
{ 
    the code..in turn also calling some sub functions such as DoExportData...and I want to be able to return the value to main from any function...
}

private int DoExportData(DataRow dr, string cmdText)
{
    try { ... } 
    catch
    { mainReturnValue = -1; }
}  
</code></pre>

<p>Thanks.</p>
