To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Mar 29th, 2007, 05:56 PM   #1
Andy574
New Member
 
Join Date: Mar 07
Posts: 1
Andy574 is an unknown quantity at this point (<10)
[2005] Listbox will not add item using system.timers

Hi,

My current code is as follows: http://www.nomorepasting.com/paste.php?pasteID=76375

The initial calls to ConsoleWrite work perfectly, the lines are added and all is well. However the timers, when they call ConsoleWrite(), do not write anything to the listbox on the form. I debugged it and the steps seem to go upto the calls to ConsoleWrite(), then step into the subroutine, but after that, do not do anything.. the timer.enabled property is not restored to true and everything stops. I'm guessing this has something to do with the fact these timer threads are calling ConsoleWrite() and not the main UI thread.. but im not sure why.

On line 29, I have simply attempted to see whether manually adding an item will change result, but this didn't work.

I also tried adding the lines GC.keepalive() for each timer in form_load, as I thought it might be the garbage collection messing with the timer after it finished.

Thanks,
Andy
Andy574 is offline   Reply With Quote
Old Mar 29th, 2007, 07:33 PM   #2
jmcilhinney
.NUT
 
jmcilhinney's Avatar
 
Join Date: May 05
Location: Sydney, Australia
Posts: 54,913
jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)
Re: [2005] Listbox will not add item using system.timers

When you create a Timers.Timer in the designer it automatically sets its SynchronizingObject property to the form its added to, thus it will raise its Elapsed events on the thread that owns that form. If you create a Timers.Timer in code then its SynchronizingObject property is Nothing by default, so it will raise its Elapsed events on a worker thread. That means that you cannot access control members directly from the Elapsed event handler. You have three choices:

1. Use delegation to marshal the method call to the thread that owns the control you want to access.

2. Set the SynchronizingObject property of the Timer to the form or a control on the form so the Elapsed event is raised in the UI thread.

3. Use a Windows.Forms.Timer instead, which is optimised for use in a Windows Forms environment.
__________________

2007, 2008, 2009, 2010

Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB | C# (ForumAccount has translated some of my VB submissions to C#)
My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET
jmcilhinney is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:49 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.