473,657 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show dialog in response to message

WP
Disclaimer: I'm new at C# so please be gentle. :-)
I'm writing a simple card game where two players play against each
other through a middle hand they both connect to. In the client (the
player) I read messages from the middle hand in an asynchronous
fashion. I ran into a problem when I tried to implement the player
repsone to the play card message and I need your help.
When the player gets the play card message I want to display a simple
dialog box displaying the cards he or she has available for play.
However, during runtime I get an InvalidOperatio nException when I
attempt to show the dialog. The more precise error message is, and
here I translate to english: The action between threads is not valid.
The control collected/gathered from another thread than the one it was
created on. Is it because the control (the dialog) tries to use an
object, created by the "main" form, holding the players cards? How
should I solve this in a proper way?

Thanks for reading and thanks for any replies!

- Eric
Mar 14 '08 #1
4 2492
On Thu, 13 Mar 2008 17:11:23 -0700, WP <mi********@gma il.comwrote:
[...]
However, during runtime I get an InvalidOperatio nException when I
attempt to show the dialog. The more precise error message is, and
here I translate to english: The action between threads is not valid.
[...]
The short answer: you need to use Control.Invoke( ) or
Control.BeginIn voke().

Do a Google search on those method names or on the English language
version of the text for the exception you're seeing.

Pete
Mar 14 '08 #2
WP
On 14 Mar, 01:32, "Peter Duniho" <NpOeStPe...@nn owslpianmk.comw rote:
On Thu, 13 Mar 2008 17:11:23 -0700, WP <mindcoo...@gma il.comwrote:
[...]
However, during runtime I get an InvalidOperatio nException when I
attempt to show the dialog. The more precise error message is, and
here I translate to english: The action between threads is not valid.
[...]

The short answer: you need to use Control.Invoke( ) or
Control.BeginIn voke().

Do a Google search on those method names or on the English language
version of the text for the exception you're seeing.

Pete
Thanks for the quick reply, Pete. After creating dialog and seeing the
exception when calling ShowDialog(), I checked if InvokeRequired was
true and it was false so I didn't think that was the solution. I will
give it another try and post back. Thanks!

- Eric
Mar 14 '08 #3
On Thu, 13 Mar 2008 17:35:44 -0700, WP <mi********@gma il.comwrote:
Thanks for the quick reply, Pete. After creating dialog and seeing the
exception when calling ShowDialog(), I checked if InvokeRequired was
true and it was false so I didn't think that was the solution. I will
give it another try and post back. Thanks!
How did you check InvokeRequired? Did you use an existing control? Or
did you create a dialog form and then check the property on that form?

Basically, without a concise-but-complete code sample from you, it's
impossible to say exactly what you're doing wrong. But your original
description sounds exactly like the cross-thread exception that's thrown
when you try to access GUI components on the wrong thread, and the
solution for that is calling Invoke() or BeginInvoke().

Pete
Mar 14 '08 #4
WP
On 14 Mar, 01:41, "Peter Duniho" <NpOeStPe...@nn owslpianmk.comw rote:
On Thu, 13 Mar 2008 17:35:44 -0700, WP <mindcoo...@gma il.comwrote:
Thanks for the quick reply, Pete. After creating dialog and seeing the
exception when calling ShowDialog(), I checked if InvokeRequired was
true and it was false so I didn't think that was the solution. I will
give it another try and post back. Thanks!

How did you check InvokeRequired? Did you use an existing control? Or
did you create a dialog form and then check the property on that form?
I checked it on the dialog after creating it.
>
Basically, without a concise-but-complete code sample from you, it's
impossible to say exactly what you're doing wrong. But your original
description sounds exactly like the cross-thread exception that's thrown
when you try to access GUI components on the wrong thread, and the
solution for that is calling Invoke() or BeginInvoke().

Pete
Here's the part of the messager handler that responds to the play card
message. I must be
misunderstandin g something about Invoke, because it didn't work.

try
{
PlayCardDialog dlg = new PlayCardDialog( this.my_cards,
placed_card);

Trace.WriteLine (dlg.InvokeRequ ired.ToString() );

foo_delegate foo = new foo_delegate(dl g.ShowDialog);

this.tracebox.W riteLine(dlg.In vokeRequired.To String()); // Prints
False

//if (dlg.ShowDialog (this) == DialogResult.OK )
if ((DialogResult) dlg.Invoke(foo, this) == DialogResult.OK )
{
this.tracebox.W riteLine("play card");
}
}
catch (Exception e)
{
this.tracebox.W riteLine(e.ToSt ring());
}

This code is from the function that is called asynchronously when a
message arrives.
this.my_cards is created in the main form when the program is
launched. It's that's what's causing problems? I have no problem
modifying in response to other messages.

Thanks!
Mar 14 '08 #5

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

Similar topics

5
2597
by: W.Guerlich | last post by:
I've got a Java servlet that delivers large database resultsets transformed to Excel with the HSSF library. In some cases it takes more than 15 minutes before transformation is done and content can be delivered to the browser. I want to show the "Save As" dialog as early as possible so the user knows he's not lost and forgotten. I already tried to send the response headers immediately after receiving the request including content...
7
3694
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a satisfactory answer (check your browser) so now that I've had the time to set up a reasonable little test that I can post somewhere, I'll try again. The app I've written has three ASPX pages. One is a combined page which writes a little text...
2
5320
by: Rez | last post by:
Hi Guys, I have a problem with exporting to excel from a modal dialog box. Basically, i have an ASPX page that gathers user criteria, and passes it to a dialogbox (showModalDialog), There is a grid on the dialog that will be populated based on the criteria. Since i am doing some postback on the dialog i have the following tag in the header: <base target="_self">
3
3821
by: ad | last post by:
I want user can confirm before delete records ? How can I show a confirm dialog when users press a button?
4
6255
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
1
1507
by: Tomas Martinez | last post by:
Hi, In my web I have a proccess of download reports which on first step generates a PDF, then flushes the buffer (the generated file) and finally deletes this file from server. Ok, the problem is that using it with Windows 2000, when the "Save as..." dialog box appears and a user clicks "Open" button, the dialog reappears and for opening the file it must be clicked again. In fact the first dialog box shows a message more or less like...
3
6431
by: =?Utf-8?B?YXNkZg==?= | last post by:
Hello. I am making a web application with c# and am using this code: Response.ContentType = "application/x-excel"; Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("あいうえお") + ".csv"); Encoding encoding = Encoding.GetEncoding("Shift-JIS"); Response.BinaryWrite(encoding.GetBytes(csvStr)); Response.End(); It works fine..the data gets saved nicely to an excel file. The user pushes the...
4
7666
by: GD | last post by:
Hi, I have the following C# code in a page: Response.ContentType = "APPLICATION/OCTET-STREAM"; Response.AppendHeader("Content-Disposition", "Attachment; Filename=\"C:\\Download.txt\"" FileInfo fileToDownload = new FileInfo("C:\\Test.txt"); Response.Flush(); Response.WriteFile(fileToDownload.FullName); Response.End();
7
4003
by: Peter | last post by:
ASP.NET 2.0 I am trying to open a Word document and Excel document from a dialog web page, what's the best way to do that? I have tried the following: Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.