473,396 Members | 1,678 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,396 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 1852
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.