Click here to Skip to main content
15,881,882 members
Home / Discussions / C#
   

C#

 
QuestionDelegates with Events Pin
Member 1116162526-Sep-16 18:01
Member 1116162526-Sep-16 18:01 
AnswerRe: Delegates with Events Pin
Pete O'Hanlon26-Sep-16 19:36
mvePete O'Hanlon26-Sep-16 19:36 
GeneralRe: Delegates with Events Pin
Rahul VB27-Sep-16 23:04
professionalRahul VB27-Sep-16 23:04 
QuestionError Making Method Async Pin
Kevin Marois24-Sep-16 12:13
professionalKevin Marois24-Sep-16 12:13 
AnswerRe: Error Making Method Async Pin
George Swan24-Sep-16 12:43
mveGeorge Swan24-Sep-16 12:43 
AnswerRe: Error Making Method Async Pin
Pete O'Hanlon24-Sep-16 21:31
mvePete O'Hanlon24-Sep-16 21:31 
SuggestionRe: Error Making Method Async Pin
Richard Deeming26-Sep-16 1:52
mveRichard Deeming26-Sep-16 1:52 
QuestionCancelRequest not work! Pin
Programmer 124-Sep-16 7:13
Programmer 124-Sep-16 7:13 
C#
/* This is a blink label user control --------------------------------*/
public partial class BlinkLabel : Label {

private CancellationTokenSource ts;
private Task task1;

public BlinkLabel()
{ 
   InitializeComponent(); 
}

public void StartBlink()
{
   ts=new CancellationTokenSource();
   CancellationToken ct = ts.Token;

   if ( isRunningTask(task1) ) return;

   task1 = Task.Factory.StartNew(() =>
   {
       while (true)
       {
           ct.ThrowIfCancellationRequested();
           Thread.Sleep(500);
           Visible = !Visible;
                    
       }
    }, ct);

    blinkTask.ContinueWith(t =>
    {
        Visible = false;

    },TaskContinuationOptions.None);

            
}

public void StopBlink()
{
    ts.Cancel();
}

}

C#
/* This is a my main form that use blink label user control--------------------------------*/
public partial class MainForm: Form
{
    public MainForm
   {
       InitializeComponent(); 
      
       blinkLabel1.Text="Blinking message...";
       blinkLabel1.StartBlink(); //Works
       blinkLabel1.StopBlink();  //Not works - blink not stop.
   }
    
}


I have some question:

1- why cancel request doesn't work?
2- how we can debug parallel program? when i use Ctrl+F5 the program works, when use F5 invoke errors occured.
3- Does exist better way to create blinkLable user control instead Task?

please get a solution for this problem, i don't have enough experience in parallel programming. thanks/.
AnswerRe: CancelRequest not work! Pin
Eddy Vluggen24-Sep-16 11:48
professionalEddy Vluggen24-Sep-16 11:48 
GeneralRe: CancelRequest not work! Pin
Programmer 124-Sep-16 19:31
Programmer 124-Sep-16 19:31 
GeneralRe: CancelRequest not work! Pin
Eddy Vluggen26-Sep-16 4:53
professionalEddy Vluggen26-Sep-16 4:53 
QuestionStrange problem in Exception handling Pin
Programmer 123-Sep-16 21:44
Programmer 123-Sep-16 21:44 
AnswerRe: Strange problem in Exception handling Pin
OriginalGriff23-Sep-16 22:36
mveOriginalGriff23-Sep-16 22:36 
GeneralRe: Strange problem in Exception handling Pin
Programmer 124-Sep-16 0:28
Programmer 124-Sep-16 0:28 
Questionhow to display alert in system tray using c# Pin
Member 308047023-Sep-16 2:18
Member 308047023-Sep-16 2:18 
AnswerRe: how to display alert in system tray using c# Pin
Pete O'Hanlon23-Sep-16 2:23
mvePete O'Hanlon23-Sep-16 2:23 
AnswerRe: how to display alert in system tray using c# Pin
Eddy Vluggen23-Sep-16 6:22
professionalEddy Vluggen23-Sep-16 6:22 
QuestionCreate own language translator in C# Pin
Member 1051770422-Sep-16 21:47
Member 1051770422-Sep-16 21:47 
AnswerRe: Create own language translator in C# Pin
Pete O'Hanlon22-Sep-16 21:57
mvePete O'Hanlon22-Sep-16 21:57 
GeneralRe: Create own language translator in C# Pin
Member 1051770423-Sep-16 0:55
Member 1051770423-Sep-16 0:55 
GeneralRe: Create own language translator in C# Pin
Pete O'Hanlon23-Sep-16 1:04
mvePete O'Hanlon23-Sep-16 1:04 
GeneralRe: Create own language translator in C# Pin
Member 1051770423-Sep-16 1:42
Member 1051770423-Sep-16 1:42 
GeneralRe: Create own language translator in C# Pin
Pete O'Hanlon23-Sep-16 1:54
mvePete O'Hanlon23-Sep-16 1:54 
GeneralRe: Create own language translator in C# Pin
Member 1051770425-Sep-16 19:42
Member 1051770425-Sep-16 19:42 
GeneralRe: Create own language translator in C# Pin
Pete O'Hanlon25-Sep-16 20:35
mvePete O'Hanlon25-Sep-16 20:35 

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.