[Mono-list] Mono, Windows Forms, and Headless operation

George, Glover E ERDC-RDE-ITL-MS Glover.E.George at erdc.dren.mil
Fri Jan 8 15:56:52 UTC 2016

Hi Timotheus,

Thanks for your reply.  Unfortunately, changing from WinExe to Exe doesn¹t
help as it still wants an X Display.  Also, most of the business logic is
separate from the gui .  However, the multithreading uses Background
Workers, which to my knowledge, requires an event loop to handle the
ProgressChanged and WorkerCompleted events.  If I don¹t display the form,
the Progress Changed event is raised, but the UI thread doesn¹t handle it.
So if I drive the business logic without any forms (which would be nice),
I¹d be forced to change the implementation to using C# threads instead of
Background Workers.  This isn¹t entirely impossible, but will take much
longer.  I have three weeks (otherwise, I wouldn¹t try to bother the list,
I¹d work it out myself :D).

Perhaps there are generic Event Loops in C# that could listen for events
from the BackgroundWorkers, but I¹ve yet to find them.

Note:  This isn¹t exactly a problem with Mono.  If I create and display
the form, from which the Background Workers are created and run, it works
fine in both Mono and Windows.  If I create the form but do not display it
(insatiate, initialize the form, and instantiate several background
workers), the UI thread terminates before the Background Workers in BOTH
Mono and Windows.  The question is really a matter of what Makes Mono
require X?  Is it the project type (doesn¹t seem to be), or is it the fact
that I¹m creating objects from the Forms object hierarchy? Also, is there
a cheap, dirty trick to just not attempt to connect to X, yet still have
the logic run?

It¹s looking more and more inevitable that if I wanted a multithreaded C#
app under mono, and require it to run without X, BackgroundWorker isn¹t a
solution.  If that¹s the case, I guess I can accept that.

‹ ‹ ‹ 

Glover E. George
Computer Scientist
Information Technology Laboratory
US Army Engineer Research and Development Center
Vicksburg, MS 39180

On 1/8/16, 1:13 AM, "mono-list-bounces at lists.ximian.com on behalf of
Timotheus Pokorra" <mono-list-bounces at lists.ximian.com on behalf of
timotheus.pokorra at solidcharity.com> wrote:

>Hello George,
>> Question First:
>> The main question I had for the Mono list is this.  Is it possible to
>> mono run Windows Forms code without trying to open X11 (I.e. headless
>> What triggers mono to request an X11 display? Is it the project type?
>>Is it
>> the call to an object that inherits from a Windows Forms control?  I
>> need to see the form, but if I¹m using BackgroundWorkers, I need the
>> event handler, don¹t I?
>You should try to modify the project type, ie OutputType in the csproj
>file, WinExe vs Exe.
>> I know this may be confusing, and if so, please feel free to ask for
>> clarifications, or even just to say ³Why would you want to do that?²
>I wonder if you could cleanly separate the business logic from the
>gui. Then you can have a dll with the business logic, which you can
>reference from your winforms forms, but also from your console
>hope this helps,
>  Timotheus
>Mono-list maillist  -  Mono-list at lists.ximian.com

More information about the Mono-list mailing list