473,378 Members | 1,639 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,378 software developers and data experts.

IPC-Remoting: Threading issue in MDI-application

Hello,

I have an Mdi-application which also is a remoting-server (Ipc).
Several instances can co-exist on the same machine.

I have a small app (search-engine) (remoting-client) which calls a sub on
the MDI (specific instance) thus retrieving eg the data of a certain customer.
If the customer childform is already instanciated, there is no problem.
If the destination-childform is not yet open, it will be opened like this:

' Create an instance of the form
If Childform.frmInstallations Is Nothing Then
Childform.frmInstallations = New frmInstallations
With Childform.frmInstallations
.MdiParent = MDI ' This variable creates a threading-issue
.Show(Commands.ReadAllowed("InstallationsOverview" ))
End With
Else

It is the assignment of the MdiParent which poses the problem.
'MDI' is a variable which references the instance of the Main (mdi) Form
(frmMain).
The generated exception is this: "Cross-thread operation not valid: Control
'frmMain' accessed from a thread other than the thread it was created on."

How can I solve this threading-issue?

TIA,
Michael
Jan 2 '08 #1
2 1813
=?Utf-8?B?TWljaGFlbCBNYWVz?= <mi**********@community.nospamwrote in
news:66**********************************@microsof t.com:
It is the assignment of the MdiParent which poses the problem.
'MDI' is a variable which references the instance of the Main (mdi)
Form (frmMain).
The generated exception is this: "Cross-thread operation not valid:
Control 'frmMain' accessed from a thread other than the thread it was
created on."

How can I solve this threading-issue?
Just Google the exceptionm you need to marshal the form to the parent
through with Control.BeginInvoke (don't use Invoke as it can deadlock).

--
sp**********@rogers.com (Do not e-mail)
Jan 2 '08 #2
Hi,

I came up with this solution:

#Region " Declarations "

Module Declarations

Friend fMdi As MainForm
Friend fChild As ChildForm

End Module

#End Region ' Declarations

#Region " ChildFroms "

Module ChildFroms

#Region " Delegates "

Delegate Sub AddChildDelegate(ByVal child As Form)

#End Region ' Delegates

Friend Sub InstanciateForm()
Dim Child As New ChildForm
Child.Text = "Do something"
Adding(Child)
End Sub

Public Sub Adding(ByVal Child As Form)
If fMdi.InvokeRequired Then
Dim AddChildDlg As New AddChildDelegate(AddressOf Adding)
fMdi.BeginInvoke(AddChildDlg, Child)
Else
Child.MdiParent = fMdi
Child.Show()
End If
End Sub
End Module

#End Region ' ChildFroms

#Region " ChildForm "

Public Class ChildForm

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox("Hello World")
End Sub

Private Sub ChildForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
fChild = Me
End Sub

End Class

#End Region ' ChildForm

#Region " MainForm "

Imports System.Threading

Public Class MainForm

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
fMdi = Me
Dim t1 As New Thread(New ThreadStart(AddressOf
ChildFroms.InstanciateForm))
t1.Start()
End Sub

End Class

#End Region ' MainForm
Regards,

Michael

"Spam Catcher" wrote:
=?Utf-8?B?TWljaGFlbCBNYWVz?= <mi**********@community.nospamwrote in
news:66**********************************@microsof t.com:
It is the assignment of the MdiParent which poses the problem.
'MDI' is a variable which references the instance of the Main (mdi)
Form (frmMain).
The generated exception is this: "Cross-thread operation not valid:
Control 'frmMain' accessed from a thread other than the thread it was
created on."

How can I solve this threading-issue?

Just Google the exceptionm you need to marshal the form to the parent
through with Control.BeginInvoke (don't use Invoke as it can deadlock).

--
sp**********@rogers.com (Do not e-mail)
Jan 3 '08 #3

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

Similar topics

1
by: Swaroop C H | last post by:
Is there a Python equivalent of Perl's IPC::Run module http://search.cpan.org/dist/IPC-Run/lib/IPC/Run.pm ] ? Thanks! -- Swaroop C H Blog: http://www.swaroopch.info Book:...
0
by: Kevin | last post by:
Configuration: Redhat AS 3.0 IBM DB2 8.1 fixpak 5 Problem: I am attempting to start a capture and get the following error message: 2004-06-10-10.46.34.625103 <Asnenv:setEnvIpcQRcvHdl>...
2
by: J | last post by:
Hello, What is the best/easiest way to setup interprocess communication between a windows service and a webservice? The windows service will be running on the same machine that is hosting the...
1
by: Andreas | last post by:
Hi, I'm developing a non-interactive C++ windows service (as support for interactive services will run out...) that shall communicate with a .net application on the local host. What's the best...
2
by: a_agaga | last post by:
Do you know are there some reasons why many do not make processes to communicate through memory? Why network connections (sockets) are used so commonly in IPC (inter process communication)...
2
by: P | last post by:
Hello. I launch two programs in a machine. These programs communicate each other by TCP socket. (OS : Windows Server 2003 x64) Here is my question. Can I use UDP instead of TCP as IPC?...
0
by: abdullah toprak | last post by:
Hi I would like to see an example, how can i write an windows service, which communicates with IPC Channel and a Form GUI. I have written some tests, but i receive an IPC-Port error: Access...
7
by: Alex Y Wang | last post by:
Hi all, my current project is completely written in native C++, and for some reason I need to write a standalone .Net program to do some work for it. Therefore, I need to find an effective way of...
7
by: adrin | last post by:
Hello, Could anybody tell me what are IPC mechanisms that .NET supports at present?(and what improvements were made in different framework versions)? Is IPC support windows dependent or is it...
0
gpraghuram
by: gpraghuram | last post by:
Hi, I have started writing some code using the IPC::Sharelite. I have written some pieces of code and i tried running the same . Following is the code #!/app/perl5.6/bin/perl use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.