473,795 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with ShowDialog() in different thread

5 New Member
Hi.
i'm using c# in net 2.0. winxp-sp2 machine.

I have a form, say FormGrid in that i have to do some work... there is a problem, related to datagridview and the datatable in the DataSource, and this problem require to work with the datatable in the same thread the dataridview is.

So, i make another thread with another form, say FormWatch to see the progress in formGrid. something like this:

In FormGrid i have something like:
Expand|Select|Wrap|Line Numbers
  1. void Process()
  2. {
  3.    Thread t = new Thread(new ThreadStart(Watcher));
  4.    t.Start();
  5.    // works begin here
  6. }
  7.  
  8. void Watcher()
  9. {
  10.    using(FormWatch frm = new FormWatch())
  11.    {
  12.       frm.ShowDialog();
  13.    }
  14. }
  15.  
FormWatch have a timer from where i see the progrees in FormGrid.

Things are almost fine... the problem is that when FormWatcher ends, the application lost focus completely, i have to clic it in the taskbar...

A workaround is to call the Activate method, something like:

Expand|Select|Wrap|Line Numbers
  1. delegate void DelegateActivate()
  2.  
  3. void ProcActivate()
  4. {
  5.    this.Activate();
  6. }
  7.  
  8. void Watcher()
  9. {
  10.    using(FormWatch frm = new FormWatch())
  11.    {
  12.       frm.ShowDialog();
  13.    }
  14.  
  15.    this.BeingInvoke(new DelegateActivate(ProcActivate));
  16. }
  17.  
(more or less, sorry if i make a typo)

This brings the application, but the flick is horrible...

¿Does anybody knows how to say FormWatch activate directly FormGrid? Or keep focus in the application?


Thanks
May 12 '07 #1
0 1783

Sign in to post your reply or Sign up for a free account.

Similar topics

1
19074
by: NanoWizard | last post by:
Enclosed below is a class that contains one member item called _frm. It is just a standard System.Windows.Forms.Form class defined elsewhere (just disregard the definition of the object). My question is if I want to start a System.Windows.Forms.Form via ShowDialog in another thread what is the best way to do it? Basically, I want to start a form, then continue executing elsewhere and occasionally posting data to the form. I know you...
6
2683
by: Steve | last post by:
Hi All, I'm having a problem displaying a form as a modal dialog window, when I call the code below from one part of my program (a right-click menu) it works fine, but when I call it from within another Sub, the new form displays but I can click back to the main form so the dialog window no longer has the focus. Here is the code I am using, does anyone know why this
5
2546
by: Mike | last post by:
Hi, I want to show form as a modal dialog and use such code: Dim frm_Zip As New frmZIP frm_Zip.ShowDialog() but instead of be as modal dialog, it is modeless - I can switch between forms. Does anybody had the same problem? OS: Win2000 Prof
0
2961
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode thread. so far so good. all contacts r added properly. now when another login adds me in his contact, i recv a subscription, so i popup a form and ask for accept/reject. this all happens in a separate thread. popup form gets opened and choice is...
7
2633
by: Simon Verona | last post by:
I have a problem in my application which I believe is due to open handles.. . The symptom that users report is that after they have been using the application for a while, it will randomly just crash with an exception report (I've not got the details of the error, but I'm working on that now!). I'm trying to reproduce the circumstances by simulating a typical batch of user tasks on my pc and monitoring whats happening. I'm guessing it's...
5
10909
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I have a form that has a button. ( this form is a child form of a parent form ( main form ). Anway...in this child form I have a button, and if clicked a bunch of code will get executed. I would like to show a Progress Bar / form in modal/ShowDialog...
4
2519
by: cyrous xiao | last post by:
I hvae three thread and a thread that is used to show a winform. The code: Thread ThreadDialog= new Thread (new ThreadStart (ShowDialog)); //Show a winform Dialog ThreadDialog.Start (); Thread Thread1= new Thread (new ThreadStart (Thread1Func)); Thread1.Start (); Thread Thread2= new Thread (new ThreadStart (Thread2Func));
14
6804
by: shark | last post by:
Hi, Does Form.ShowDialog() start new thread ? If yes how is solved cross-thread operations? Thx
6
4500
by: Scott Gravenhorst | last post by:
Windows XP SP3 My application is set to open a SaveFile dialog when an exit is requested. When I click the app's close button, the save dialog opens, but when I click to change the folder, the exception occurs pointing to FileSaveDialog1.ShowDialog(). The exception also indicates some problem with system.drawing.dll. The exception text is: "Attempted to read or write protected memory. This is often an
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10438
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...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
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...
1
7540
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
6780
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
5437
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...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.