Tech Off Post

Single Post Permalink

View Thread: I was told today to not worry cross-thread execution when...
  • User profile image
    Verdant

    ....Using multiple threads, we were taught to just run the code outside vs and the debugger, which seems to work, but also seems completly wrong to me.

    From a WinForms Form Object:

    tKey = new Thread(ReadKeyboard);

    public void ReadKeyboard()
    {
        Text = "Keyboard acquired";
    }

    can someone verify that this is bad practice or otherwise?

    i don't like skipping the debugger, so i used:
    main.Invoke(new MethodInvoker(delegate() { Text = "Keyboard acquired"; }));

    is this an acceptable "workaround"?

    edit: main being a reference to the form object