Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
QuestionAODL ans .xls files Pin
SummerBulb13-Jun-10 21:34
SummerBulb13-Jun-10 21:34 
QuestionDatagridview CellValidating [Solved] Pin
jojoba201113-Jun-10 21:34
jojoba201113-Jun-10 21:34 
QuestionReport Service - passing XML paramter to filter data Pin
thenewbee13-Jun-10 21:21
thenewbee13-Jun-10 21:21 
QuestionData Passing between two different Application Pin
Priyagdpl13-Jun-10 20:06
Priyagdpl13-Jun-10 20:06 
AnswerRe: Data Passing between two different Application Pin
Md. Marufuzzaman13-Jun-10 20:31
professionalMd. Marufuzzaman13-Jun-10 20:31 
AnswerRe: Data Passing between two different Application Pin
Abhinav S13-Jun-10 21:45
Abhinav S13-Jun-10 21:45 
QuestionDo stuff while button pressed down? [solved] Pin
la0113-Jun-10 16:52
la0113-Jun-10 16:52 
AnswerRe: Do stuff while button pressed down? Pin
Luc Pattyn13-Jun-10 17:18
sitebuilderLuc Pattyn13-Jun-10 17:18 
Hi,

your label1.Invoke causes the entire while loop to execute on the main thread (so it is allowed to touch the Label), however that also blocks the thread, so your button1_MouseUp handler cannot react to the button being released. (The main thread processes its event queue, popping and executing one message at a time).

Furthermore, your while loop does not contain any timing control (such as a Thread.Sleep), so it will spin as fast as it can (depending on the characteristics and the load of your system), and clogging your Console.

I would use a very different approach, without BGW:
- have a class member of type System.Windows.Forms.Timer;
- have a class member "int tickCount";
- in button1_MouseDown clear tickCount and launch that timer, with an appropriate interval (say 100 msec), and a tick handler basically containing:
Console.WriteLine("down");
tickCount++;
label1.Text=tickCount.ToString();

- in button1_MouseUp simply stop the timer.

The advantages would be: code is much simpler, everything runs on the main thread, which is idle most of the time, as all it does is run one tick handler every 100 msec.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

Nil Volentibus Arduum

GeneralRe: Do stuff while button pressed down? Pin
la0113-Jun-10 17:46
la0113-Jun-10 17:46 
GeneralRe: Do stuff while button pressed down? Pin
Luc Pattyn13-Jun-10 18:02
sitebuilderLuc Pattyn13-Jun-10 18:02 
GeneralRe: Do stuff while button pressed down? Pin
la0115-Jun-10 13:33
la0115-Jun-10 13:33 
Questionneed help Pin
aaga513-Jun-10 9:56
aaga513-Jun-10 9:56 
AnswerRe: need help Pin
Luc Pattyn13-Jun-10 10:03
sitebuilderLuc Pattyn13-Jun-10 10:03 
AnswerRe: need help Pin
Lutosław13-Jun-10 12:26
Lutosław13-Jun-10 12:26 
AnswerRe: need help Pin
Abhinav S13-Jun-10 18:18
Abhinav S13-Jun-10 18:18 
QuestionProblem to use letters ( c: , d:) with the physical drive: Pin
muteb13-Jun-10 7:32
muteb13-Jun-10 7:32 
AnswerRe: Problem to use letters ( c: , d:) with the physical drive: Pin
Henry Minute13-Jun-10 8:14
Henry Minute13-Jun-10 8:14 
AnswerRe: Problem to use letters ( c: , d:) with the physical drive: Pin
Luc Pattyn13-Jun-10 8:21
sitebuilderLuc Pattyn13-Jun-10 8:21 
QuestionConnection string Pin
humayunlalzad13-Jun-10 3:01
humayunlalzad13-Jun-10 3:01 
AnswerRe: Connection string Pin
Abhinav S13-Jun-10 3:27
Abhinav S13-Jun-10 3:27 
GeneralRe: Connection string Pin
humayunlalzad13-Jun-10 3:51
humayunlalzad13-Jun-10 3:51 
Questioncrystal report and list<> Pin
reza assar12-Jun-10 21:39
reza assar12-Jun-10 21:39 
AnswerRe: crystal report and list Pin
Mycroft Holmes13-Jun-10 19:55
professionalMycroft Holmes13-Jun-10 19:55 
QuestionNeed to add 1 to a cache value Pin
Randall Hall12-Jun-10 18:07
Randall Hall12-Jun-10 18:07 
AnswerRe: Need to add 1 to a cache value Pin
Dan Mos12-Jun-10 18:21
Dan Mos12-Jun-10 18:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.