tags:

views:

86

answers:

3
class Program
{
    static String ChannelName = null;
    static Form1 f;

    static void Main()
    {
        f = new Form1();
        f.Show();
        try
        {
            MY CODE WHICH CALLS INTO ANOTHER CLASS BUT CANNOT PASS THE GUI INSTANCE AS
            IT USES REMOTING
        }
    }
}

I know this isnt the best/normal way to do it, but i need to write data to the GUI from a class which has bo instance of the GUI so i was going to call Program.method() and use a function to write to the GUI in program. However when i run the above my GUI displays but with the windows hourglass?

Could someone show me a quick fix so that i can still crudely show the GUI, let the application code run and then later write to the GUI?

A: 

You could move your try block to the Form.Shown event to allow your form to be shown before it begins processing.

Adam Driscoll
+3  A: 

You need to call the Form.ShowDialog method.

    static void Main(string[] args)
    {
        f = new Form1();

        try
        {
            f.label1.Text = "Changed Label from Console!";
            f.textBox1.Text = "Changed Textbox from Console!";
        }
        catch (Exception)
        {

            throw;
        }

        f.ShowDialog();
    }

Should make it work.

Shaharyar
Hey, ok the GUI works fine (THANK YOU!!) but it would appear my CODE after it is now not executing, asif the GUI acts like a while loop?
Tom
Yes, because the code in the try-catch will be executed only after closing the modal Form (that's what you get by calling ShowDialog method) ...
digEmAll
Just put the try clause before the ShowDialog() method. (Updated Answer)
Shaharyar
+1  A: 

Hey guys i did it in the end! I put my GUI creation into a thread and gave my gui class a methodinvoker which allows me to use a delegate to write to it from another thread.

My data class calls a method in program, which sends the string to write to the methodinvoker in the gui and wala!

Thanks for your ideas and help!

Tom
+1 I was just writing an answer like this ;)
digEmAll