472,985 Members | 2,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Demo Mode

I need to show few forms in sequential order, one after another with an
interval of approx 10 sec. What would be the best way out using Timers?
Jul 21 '05 #1
4 1847
By specifying 10 seconds as criteria, you are specifying the need for a timer. Why isn't a timer viable?

I must admit that this seems kinda silly, but here it goes:

using System;
using System.Windows.Forms;
using System.Threading;

public class FormSlideShow
{
private int complete = 0;

/// <param name="timeout">Number of milliseconds each form is shown.</param>
public void ShowForms(int timeout, params Form[] forms)
{
foreach (Form form in forms)
{
if (form.InvokeRequired)
form.Invoke(new MethodInvoker(form.Show));
else
form.Show();

// This should NOT be a System.Windows.Forms.Timer
// The callback is on a ThreadPool thread. Do not use the forms to call any Begin* inovcations or
// run any more Timer classes. (to prevent dead-locks)
using (System.Threading.Timer timer = new System.Threading.Timer(
new TimerCallback(HideForm), form, timeout, Timeout.Infinite))
{
while (complete == 0)
Application.DoEvents();

System.Threading.Interlocked.Exchange(ref complete, 0);
}
}
}
private void HideForm(object state)
{
Form form = state as Form;

try
{
if (form.InvokeRequired)
form.Invoke(new MethodInvoker(form.Close));
else
form.Close();
}
finally
{
System.Threading.Interlocked.Exchange(ref complete, 1);
}
}
}
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"VB User" <VB****@discussions.microsoft.com> wrote in message news:68**********************************@microsof t.com...
I need to show few forms in sequential order, one after another with an
interval of approx 10 sec. What would be the best way out using Timers?

Jul 21 '05 #2
sorry, i misunderstood when u said "out using Timers" as "without using Times" :)

anyway, the code i posted will work, but may not be the most elegant solution. If performance is not an issue, this will work fine.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"VB User" <VB****@discussions.microsoft.com> wrote in message news:68**********************************@microsof t.com...
I need to show few forms in sequential order, one after another with an
interval of approx 10 sec. What would be the best way out using Timers?

Jul 21 '05 #3
Can you translate this code for VB.NET?
"Dave" wrote:
sorry, i misunderstood when u said "out using Timers" as "without using Times" :)

anyway, the code i posted will work, but may not be the most elegant solution. If performance is not an issue, this will work fine.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"VB User" <VB****@discussions.microsoft.com> wrote in message news:68**********************************@microsof t.com...
I need to show few forms in sequential order, one after another with an
interval of approx 10 sec. What would be the best way out using Timers?


Jul 21 '05 #4
Probably not correctly :)

I can tell you that the MethodInvoker delegate is in the System.Windows.Forms namespace, and that the TimerCallback delegate is in
the System.Threading namespace.

I'm not sure how you would invoke them using VB.NET, but I imagine it must be similar.

I'm pretty sure that VB.NET doesn't have a "using" block as the one I've used here:

using (System.Threading.Timer timer = new System.Threading.Timer(
new TimerCallback(HideForm), form, timeout, Timeout.Infinite))
{
while (complete == 0)
Application.DoEvents();

System.Threading.Interlocked.Exchange(ref complete, 0);
}

so, instead... just do this (in VB, of course):

Dim timer As System.Threading.Timer

Try
timer = new System.Threading.Timer(new TimerCallback(HideForm), form, timeout, Timeout.Infinite))

while (complete = 0)
Application.DoEvents()
end while ??

System.Threading.Interlocked.Exchange(ByRef complete, 0)
Finally ??
timer.Dispose()
End Try ??
The rest of the conversions are probably intuitive, i.e. delete ";"'s at the end of each line, change the way you dimension
variables, replace { } blocks with "name"..."End name", etc.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"VB User" <VB****@discussions.microsoft.com> wrote in message news:D2**********************************@microsof t.com...
Can you translate this code for VB.NET?
"Dave" wrote:
sorry, i misunderstood when u said "out using Timers" as "without using Times" :)

anyway, the code i posted will work, but may not be the most elegant solution. If performance is not an issue, this will work
fine.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"VB User" <VB****@discussions.microsoft.com> wrote in message news:68**********************************@microsof t.com...
>I need to show few forms in sequential order, one after another with an
> interval of approx 10 sec. What would be the best way out using Timers?


Jul 21 '05 #5

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

Similar topics

0
by: Doug Farrell | last post by:
Hi all, I just installed the wxPython-2.4.1.2 demo RPM on my RedHat Linux 9.0 machine, which has Python 2.2.2 on it, and I'm having a problem running the demo.py program. Here is a trace of the...
2
by: C GIllespie | last post by:
Dear All, I have wxpython under both windows and Linux. Under Windows there is a nice little demo, which demonstrates all the widgets (with accompanied source code). I presume the same demo...
1
by: Ken Dere | last post by:
I am running Suse 9.0 with python 2.3-52 and python-wxGTK 2.4.1.2-43. Everything has been installed from the CD distribution and should work together. when trying to run the demo, I get: ...
2
by: Bryan | last post by:
just for fun and my own experience, i wanted to use py2exe to wrap the wxpython demo. i put the setup script in the demo directory which is the following: from distutils.core import setup...
1
by: John Kinson | last post by:
Hi, I'm trying to get the wxPython demo to run on a Debian sarge testing installation, but encounter the following error when I run the demo script: # ./demo.py Traceback (most recent call...
7
by: Ernie | last post by:
I am trying out the quixote 1.0 demo in my linux box. I am able to view the main demo page using http://localhost/cgi-bin/demo.cgi with the HelloWorld on top of the page but I was wondering where...
5
by: sundew | last post by:
Here I am presenting you the new Wednus proj. subtree, Wednus DHTML RPG engine, or just 'Wednus RPG' with a demo game using the engine. About the engine itself, since this DHTML game engine...
1
by: Sean | last post by:
I have a login control which I want to have loaded my demo user name and the demo password. Naturally the demo password doesnt have to show as text literal but best I can tell I cant set the...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
5
by: Andrew P | last post by:
Hello, I am new (very) to Python and have just down loaded the latest version of Python (2.5) and WXPython (2.8). For some reason I cannot get the WXPython demo to run at all. I run windows...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.