0

i have read this question How to Create Form from within non gui thread C# but it didnt helped me.

I have a List of Tables which has a List of Players and each Player has his own Form (i seperated it in player.cs and playerform.cs)

The Problem is: if i make the Table inherited from Form (Show the Form and make visible=false, so its not shown) then i can make an Methodinvoker

//table.cs
class Table : Form{

    var player = Players.First();
    this.Invoke(new MethodInvoker(player.ShowForm));

//player.cs
void ShowForm() {
    var form = new PlayerForm();
    form.show();
}

this is working, without any problems or sideeffects. but a little nasty, inherit the Class from Form, just to use Invoke. (my table dont need a Form, so i want to fix this)

how can i use invoke, if i dont have a form?

thanks

Community
  • 1
  • 1
Tim Kretschmer
  • 2,272
  • 1
  • 22
  • 35

1 Answers1

2

I would suggest that you not try to create forms on the non-UI thread unless you have a very compelling reason to do so. Doing that creates complexity that can be avoided by using other, more standard approaches.

For example, if you want processing to happen in the background for each form, you can use a BackgroundWorker instance for each separate form.

If you have a long-running process, such as indicated in the question you link to, that process can use an event to request that a form be shown via the standard UI thread.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • the forms for each player are just 55x50px and displaying a few stats, and i want to seperate it nicely as a MVC. – Tim Kretschmer Aug 07 '12 at 04:11
  • You don't need to run each form on a separate thread to achieve a solid design. For one approach to MVC with WinForms have a look at http://www.codeproject.com/Articles/383153/The-Model-View-Controller-MVC-Pattern-with-Csharp – Eric J. Aug 07 '12 at 08:26