473,789 Members | 2,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer.Tick event not firing

I have an application that uses a timer. I've created a function
called TickEvent that I "assigned" to the timer1.Tick event:

this.timer1.Int erval = 1000;
this.timer1.Tic k += new System.EventHan dler(this.TickE vent);
....
private void TickEvent(objec t sender, System.EventArg s e)
{
liSecondsElapse d++;
DateTime lsTime = Convert.ToDateT ime(liSecondsEl apsed);
lblTimer.Text = lsTime.Hour.ToS tring() + ":" +
lsTime.Minute.T oString() + ":" + lsTime.Second.T oString();
lblTimer.Refres h();
}

In my main click event, I have the following:

private void miGetAceMap_Cli ck(object sender, System.EventArg s e)
{
lsCurrentFolder Path = lsRootFolderPat h;
txtOutput.Visib le = true;

ThreadStart timerWorker = new ThreadStart(Sta rt_Timer);
Thread tTimer = new Thread(timerWor ker);
tTimer.Start();

ThreadStart worker = new ThreadStart(Get _Folders_Simple );
Thread t = new Thread(worker);
t.Start();

t.Join();
tTimer.Join();
timer1.Stop();
this.lblStatus. Text = "Complete";
liFolderCounter--;
lblFolderCount. Text = "Found " + liFolderCounter .ToString() + "
folders";
}

private void Start_Timer()
{
timer1.Enabled = true;
timer1.Start();
}

My TickEvent doesn't ever seem to fire because the elapsed time is
never displayed in the lblTimer label.

Can someone please help???

Thanks!

Nov 17 '05 #1
5 16051

"Jason" <ja************ *@hotmail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
I have an application that uses a timer. I've created a function
called TickEvent that I "assigned" to the timer1.Tick event:

this.timer1.Int erval = 1000;
this.timer1.Tic k += new System.EventHan dler(this.TickE vent);
...
private void TickEvent(objec t sender, System.EventArg s e)
{
liSecondsElapse d++;
DateTime lsTime = Convert.ToDateT ime(liSecondsEl apsed);
lblTimer.Text = lsTime.Hour.ToS tring() + ":" +
lsTime.Minute.T oString() + ":" + lsTime.Second.T oString();
lblTimer.Refres h();
}

In my main click event, I have the following:

private void miGetAceMap_Cli ck(object sender, System.EventArg s e)
{
lsCurrentFolder Path = lsRootFolderPat h;
txtOutput.Visib le = true;

ThreadStart timerWorker = new ThreadStart(Sta rt_Timer);
Thread tTimer = new Thread(timerWor ker);
tTimer.Start();

ThreadStart worker = new ThreadStart(Get _Folders_Simple );
Thread t = new Thread(worker);
t.Start();

t.Join();
tTimer.Join();
timer1.Stop();
this.lblStatus. Text = "Complete";
liFolderCounter--;
lblFolderCount. Text = "Found " + liFolderCounter .ToString() + "
folders";
}

private void Start_Timer()
{
timer1.Enabled = true;
timer1.Start();
}

My TickEvent doesn't ever seem to fire because the elapsed time is
never displayed in the lblTimer label.

Can someone please help???

Thanks!


What are you doing in Get_Folders_Sim ple?
Is it possible that this thread procedure retuns before the timer expires?
I see no reason to start a timer using a thread, threads are expensive
resources you know!

Willy.


Nov 17 '05 #2
Well, I just learned how to use threads, so I thought why not...

This is also my first time with the Timer control. I thought the
instance of the timer ran until you manually stopped it?

Anyway, this is the Get_Folder_Simp le function. It's recursive and
finds all of the NTFS permissions of a given folder and all of it's
subfolders. Then it places all of the NTFS information into a typed
DataSet that can be exported to XML.

private void Get_Folders_Sim ple()
{
txtOutput.Text += lsCurrentFolder Path + System.Environm ent.NewLine;
string[] laSplit = lsCurrentFolder Path.Split('\\' );
string lsName = laSplit[laSplit.GetUppe rBound(0)];

DataRow loDRsubDirector y = dsDirectory.Tab les[0].NewRow();
loDRsubDirector y["ID"] = liFolderCounter ;
loDRsubDirector y["Name"] = lsName;
loDRsubDirector y["Path"] = lsCurrentFolder Path;
dsDirectory.Tab les[0].Rows.Add(loDRs ubDirectory);

string lsString = lsCurrentFolder Path.Replace(@" \", @"\\");
ManagementObjec t lfs = new
ManagementObjec t(@"Win32_Logic alFileSecurityS etting.Path='" + lsString
+ "'");

ManagementBaseO bject outP = lfs.InvokeMetho d("GetSecurityD escriptor",
null, null);
if (((uint)(outP.P roperties["ReturnValu e"].Value)) == 0)
{
ManagementBaseO bject Descriptor =
((ManagementBas eObject)(outP.P roperties["Descriptor "].Value));
ManagementBaseO bject[] DaclObject =
((ManagementBas eObject[])(Descriptor.Pr operties["Dacl"].Value));
DumpACEs(DaclOb ject);
}
liFolderCounter ++;

DirectoryInfo d = new DirectoryInfo(l sCurrentFolderP ath);
DirectoryInfo[] dis = d.GetDirectorie s();
foreach(Directo ryInfo di in dis)
{
try
{
lsCurrentFolder Path = di.FullName.ToS tring();

this.lblStatusL abel.Text = "Enumeratin g folder: ";
this.lblStatusL abel.Refresh();
this.lblStatus. Text = lsCurrentFolder Path;
this.lblStatus. Refresh();
Get_Folders_Sim ple();
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Error parsing folder " +
lsCurrentFolder Path);
this.Close();
}
}
}

Nov 17 '05 #3
Also, I've tried enabling and starting the timer in the main thread and
it still doesn't seem to work.

Nov 17 '05 #4

"Jason" <ja************ *@hotmail.com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
Well, I just learned how to use threads, so I thought why not...

This is also my first time with the Timer control. I thought the
instance of the timer ran until you manually stopped it?

Anyway, this is the Get_Folder_Simp le function. It's recursive and
finds all of the NTFS permissions of a given folder and all of it's
subfolders. Then it places all of the NTFS information into a typed
DataSet that can be exported to XML.

private void Get_Folders_Sim ple()
{
txtOutput.Text += lsCurrentFolder Path + System.Environm ent.NewLine;
string[] laSplit = lsCurrentFolder Path.Split('\\' );
string lsName = laSplit[laSplit.GetUppe rBound(0)];

DataRow loDRsubDirector y = dsDirectory.Tab les[0].NewRow();
loDRsubDirector y["ID"] = liFolderCounter ;
loDRsubDirector y["Name"] = lsName;
loDRsubDirector y["Path"] = lsCurrentFolder Path;
dsDirectory.Tab les[0].Rows.Add(loDRs ubDirectory);

string lsString = lsCurrentFolder Path.Replace(@" \", @"\\");
ManagementObjec t lfs = new
ManagementObjec t(@"Win32_Logic alFileSecurityS etting.Path='" + lsString
+ "'");

ManagementBaseO bject outP = lfs.InvokeMetho d("GetSecurityD escriptor",
null, null);
if (((uint)(outP.P roperties["ReturnValu e"].Value)) == 0)
{
ManagementBaseO bject Descriptor =
((ManagementBas eObject)(outP.P roperties["Descriptor "].Value));
ManagementBaseO bject[] DaclObject =
((ManagementBas eObject[])(Descriptor.Pr operties["Dacl"].Value));
DumpACEs(DaclOb ject);
}
liFolderCounter ++;

DirectoryInfo d = new DirectoryInfo(l sCurrentFolderP ath);
DirectoryInfo[] dis = d.GetDirectorie s();
foreach(Directo ryInfo di in dis)
{
try
{
lsCurrentFolder Path = di.FullName.ToS tring();

this.lblStatusL abel.Text = "Enumeratin g folder: ";
this.lblStatusL abel.Refresh();
this.lblStatus. Text = lsCurrentFolder Path;
this.lblStatus. Refresh();
Get_Folders_Sim ple();
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Error parsing folder " +
lsCurrentFolder Path);
this.Close();
}
}
}


I see two major problems with your code:
1. you are updating the UI from a NON UI Thread, this is not allowed in
Windows, you should marshal the call using Control.Invoke or BeginInvoke.
2. What if an exception is being thrown in the firts part of the thread
procedure? The procedure will return and the Timer will be stopped probably
before it gets fired the first time.
I suggest you start debugging ;-)

Willy.


Nov 17 '05 #5
Can you supply any examples of marshalling? Is this the same as
delegates? I tried using delegates to update the UI from the child
thread from examples off of MSDN, but couldn't ever get it to work.

Nov 17 '05 #6

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

Similar topics

3
2966
by: Lloyd Sheen | last post by:
I have a problem where I cannot read (all the time) a file when caught by the FileSystemWatcher. What I have done to get past this is create an array of events (when I receive one I add it to the list). I then enable a timer which will attempt to process the first one in the list. The timer code is never executed. There is a handles clause on the timer and using the debugger I have watched the code for the FileSystemWatcher execute. ...
13
7499
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on it, a frontend and a backend. Case 1: If vba code on the frontend updates many rows (360,000) on the backend, a form's timer event (from the frontend) will stop firing until the user gives the form focus. (Note that the update itself always...
8
2788
by: Daniel P. | last post by:
I'm trying to set a timer that gets called every 3 seconds so I can update a field in the UI with the time elapsed since the process started. What am I doing wrong that timerDF_Tick does not get called? private System.Windows.Forms.Timer timerDF; this.timerDF = new System.Windows.Forms.Timer(this.components);
7
2387
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly reset I put some extra code in the subs that enable and disable the timer. They fire as expected. To test this I added a second timer with a 1 second interval. The event for this time would output the enabled status of the first timer and its...
4
3342
by: Dan | last post by:
Hi, I have a timer on a form (System.Windows.Forms.Timer - Framework 1.1) that is set to 60 seconds as sort an of inactivity monitor. If 60 seconds have elapsed without any user activity I want the form to close. I stop/start the timer at button clicks and keydown events etc of the various controls on the form. Users have reported the form closing in the middle of them typing or immediately after opening the form (but only rarely)....
9
7262
by: Brett | last post by:
I have a timer enabled on a form with an interval of 200. I place a break point on the first line in the timer tick event, which is a try. After a few events go on, the timer seems to stop. My break point is no longer hit. In the debugger, the timer shows enabled and the interval is still set. Any ideas what may be happening or something else I can check? Thanks, Brett
11
7565
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the code in the .elapsed event takes 1 secocond to complete, what happens? 1) Timer starts. 10 milliseconds later the code is executed and timer stops. When code is done, 1 seconds later, the timer continues. 10 milliseconds later the code is...
8
3563
by: RobcPettit | last post by:
Hi Im using System.Timers.Timer myTimer = new System.Timers.Timer(); myTimer.Elapsed += new ElapsedEventHandler(onTimer); myTimer.Interval = 1000; myTimer.Start(); and getting error onTimer does not exist in the current context. Any Ideas Regards Robert
16
3258
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not do it. If I bring this same code outside this event handler, it works just fine. Is this normal?
0
9511
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
10408
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
10199
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
9983
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...
0
6769
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
5417
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
4092
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
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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.