473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Showing Form using .NET Remoting

I have a Form class that can be open by parent Form or by .NET Remoting
command.
When the parent Form opens the Form - All fine !
But when the .NET Remoting command is trying to Show the Form, the Form
stuck !! I tried to change the Remoting delegate invocation to asynchronous
and to synchronous, yet both cause the same Form Show() to stuck.
When I mean stuck, I mean the the Form is shown but non of it controls are
shown, only gray window that does not respond.

Both the parent Form and the Remoting command are invoking the same method
to Showing the Form, here is the code:

public void OpenViewForm(bool topMost)
{
m_Viewer = new ViewerForm();
m_Viewer.TopMost = topMost;
m_Viewer.Show();
m_Viewer.BringToFront();
}

Any idea why the remoting cause this and how can I fix this?
---------
Thanks
Sharon
Nov 17 '05 #1
2 2468
Ok, I found the problem:

The remoting method is being called on a seperate thread to the main thread
- therefore it has no message loop.

The remoting class must have to have access to one of the elements of the UI
(e.g. the main form).

Then calling a method on this form using Invoke, and bringing up of the form
in there.

i.e.

public class MainForm : Form
{
static MainForm m_formCurrent = null;

static public Current
{
get
{
return m_form;
}
}

private Viewer m_Viewer;

public MainForm()
{
m_formCurrent = this;
// etc etc
}

public void OpenViewForm()
{
m_Viewer = new ViewerForm();
m_Viewer.Show();
m_Viewer.BringToFront();
}
}

// in theremoting class
MainForm.Current.Invoke(new MethodInvoker(MainForm.Current.OpenViewForm));

All calls to the viewer should be marshalled like this : by using delegates.
Nov 17 '05 #2
Thats because the remoting call is coming in on a threadpool thread which does not run a message pump.

In your Main of the remote process do something like

Form1 f ;
delegate void ShowFormDel();

static void Main()
{
f = new Form1();
RemotingConfiguration.Configure(...);
Application.Run();
}

Then in the remoted call say
f.BeginInvoke(new ShowFormDel(f.Show), new object[]{});

Now this will marshall the call to show on to the UI thread which is running a message pump and so will show the form successfully.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I have a Form class that can be open by parent Form or by .NET Remoting
command.
When the parent Form opens the Form - All fine !
But when the .NET Remoting command is trying to Show the Form, the Form
stuck !! I tried to change the Remoting delegate invocation to asynchronous
and to synchronous, yet both cause the same Form Show() to stuck.
When I mean stuck, I mean the the Form is shown but non of it controls are
shown, only gray window that does not respond.

Both the parent Form and the Remoting command are invoking the same method
to Showing the Form, here is the code:

public void OpenViewForm(bool topMost)
{
m_Viewer = new ViewerForm();
m_Viewer.TopMost = topMost;
m_Viewer.Show();
m_Viewer.BringToFront();
}

Any idea why the remoting cause this and how can I fix this?
---------
Thanks
Sharon

[microsoft.public.dotnet.languages.csharp]
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: menkaur | last post by:
I was writing simple test program for using class libraries (OS: Windows 2003 Server). The problem I’ve got: runtime error: ------------------------------------------- An unhandled exception of...
1
by: Claire | last post by:
I've written a Windows Service application that monitors input through a com port. It's been requested that I add a dialog box so that, should anyone need to watch the input for troubleshooting...
3
by: Rob | last post by:
Can a form be opened from a Windows service? I have a windows service that I would like to open a form from a notify icon. I cannot get the Notify Icon to display nor can I open a form. Any...
0
by: feng | last post by:
Hi, I am having a strange problem right now and I don't even know how to go about it. Someone please help me! Any inputs will be highly appreciated. We have an application that has a VB.Net...
5
by: Szafranr | last post by:
Hi everyone, I have NT service from which I try to display window form. This form is created in sub New. In servise I implemented OnCustomCommand handle, when I wait for command 129 and for...
3
by: tman | last post by:
OK so I built this Windows Service which was able to use MessageBox.Show to present text to the user from within the service. I had to use a special property though within that method- which is...
1
by: abc | last post by:
How to decide the best choice between web-form and win-form for the next solution? In my case, the new projects will have over 200 users to use and we will apply part-by-part function components...
7
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I am trying to see if I can call a Library remotely. The library contains a Form that I want to display then pass back some data to user that called this form remotely. I have it working...
7
by: =?Utf-8?B?TWF0dA==?= | last post by:
Hi I have an app that runs without a main form, just a notification icon, when the user clicks the icon the form is shown, and when the form is minimized it's hidden. This all works great,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.