473,320 Members | 1,870 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,320 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 1850
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.