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

Home Posts Topics Members FAQ

Windows Form and Thread question


I and trying to detect idle time or sorts in the applications I'm
building.
To do this the main Form also inherits from IMessageFilter and I
listen for WM_MOUSEMOVE. When that happens I reset a DateTime.

To check the time between last mouse move I have a timer
(System.Threadi ng.Timer)
If the the DateTime math meets a certain threshold I want to show our
login dialog, essentially locking people out of this unattended app.

When I try and ShowDialog() on my login form I get a threading error
because of the owner I try and pass in.

this failed so I tried packing up the main form in the thread so it
was passed as an argument (object state) of the timer and use that
instead of this in the timer callback but that didn't work either.

what's the proper way to show the login dialog when shown because of a
timer?

thanks
mike

Jul 25 '07 #1
1 1963
Michael,

It appears that you are using the timer in the System.Timers namespace
or the System.Threadin g.Timer class, and not the timer in the
System.Windows. Forms.Timer component. This is fine, but this means that the
thread that the event fires on is not guaranteed to be on the UI thread.

What you have to do is create a method which will call ShowDialog, and
then a delegate with a signature that matches the signature of the method
which will perform this call. Then, pass an instance of that delegate to
the Invoke method on a control on the form (or the form itself) and the call
to ShowDialog will be performed on the UI thread.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Michael Howes" <mh****@xforteb io.comwrote in message
news:eZ******** ******@TK2MSFTN GP06.phx.gbl...
>
I and trying to detect idle time or sorts in the applications I'm
building.
To do this the main Form also inherits from IMessageFilter and I listen
for WM_MOUSEMOVE. When that happens I reset a DateTime.

To check the time between last mouse move I have a timer
(System.Threadi ng.Timer)
If the the DateTime math meets a certain threshold I want to show our
login dialog, essentially locking people out of this unattended app.

When I try and ShowDialog() on my login form I get a threading error
because of the owner I try and pass in.

this failed so I tried packing up the main form in the thread so it was
passed as an argument (object state) of the timer and use that instead of
this in the timer callback but that didn't work either.

what's the proper way to show the login dialog when shown because of a
timer?

thanks
mike
Jul 25 '07 #2

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

Similar topics

5
3622
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug puposes only and is not normally visable to the user.) The Thread function is actually in the Form class. Now.. What I am seeing is that when I create an instance of this Class Library's Form, which starts the worker thread, it seems to hose up...
6
2547
by: Ayende Rahien | last post by:
Excetremely annoying problem, I've an application with a long startup time. So I created another form with my logo in it to as a splash screen. The splash screen is run from another thread and is communicated solely through static method and Invoke()'s However, when I close my second form, the first one (main window) is hiding under all the windows on the desktop. If I don't close the splash screen, then everything is fine. I tried...
3
7395
by: Brian Keating EI9FXB | last post by:
Hello again, I've already placed a few posts on this topic. This time i've a simple application that exhibits my problem, I've placed sample solution 8k on my website should anyone be interested in having a look. http://briankeating.net/transfer/test.zip To recap the problem I expected (and found). I've a main GUI thead (main form), this GUI thread has an UpdateTextBox function that appends a string in a textbox and It also has a button...
11
2220
by: DW | last post by:
I've gotten this question a couple of times in interviews and I don't know what they are looking for: How do you update a control's property, such as a textbox.text property, from a thread, in .NET? It seems to me you just update it normally. What are the interviewers looking for here? Thanks. - W
4
1554
by: BrianDH | last post by:
Hi I have an application with 3 windows forms. One of which I load at startup but hide, then show/hide based on users click. How can I test to see if the windows is hidden, or is at the moment being shown? Thanks BrianDH
2
6888
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app (which is the UI used to adjust the actions taken by, and the schedule of the service), then a privileged user thread should be used in the UI - no service required. But... "A windows service enables the creation of long-running executable
0
879
by: Freddy Rose | last post by:
Hi. I am building a basic Windows forms application that has to synchronize some databases. I want to make the synchronization functions run on a separate thread than the main form so the user can still have control of the form. This is how I am thinking about doing it. The main object that does the work will be created and run on a separate thread from the main form, then fire events that will be raised in the form. Just wondering if...
15
4760
by: Angelo | last post by:
Hi all, I'm using a FileSystemWatcher to monitor a directory. I want the FSW to pop up my already instantiated but invisible form. However, I'm running into some problems with this. 1) In the FSW.Changed FileSystemEventhandler, I called the Show method 'frmMain.Show( )' on my form, the form appears but not completely painted and it appears to be hanging with the hourglass.
9
1796
by: Scott Stark | last post by:
Hello, I'm *just* delving into Windows forms-based programming without the benefit of any books, etc. I have a background in light ASP.NET work, so forgive me if this is a really basic question related to Windows GUI. I've created a "Form1.vb" file in my project, added a menustrip, etc. When a user clicks on a menu item, how do I get it to show a new form in the same window?
0
8315
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
8829
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
8734
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...
1
8508
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
7341
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 project—planning, coding, testing, and deployment—without 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...
0
5633
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
4164
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
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
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.