Click here to Skip to main content
15,897,371 members
Home / Discussions / C#
   

C#

 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 13:40
Jacob Dixon12-Apr-10 13:40 
AnswerRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 14:38
Jacob Dixon12-Apr-10 14:38 
GeneralRe: Stopping threads (semi-safely).... Pin
DaveyM6912-Apr-10 14:46
professionalDaveyM6912-Apr-10 14:46 
AnswerRe: Stopping threads (semi-safely).... Pin
DaveyM6912-Apr-10 14:44
professionalDaveyM6912-Apr-10 14:44 
QuestionMultithreaded drawing Pin
Groulien12-Apr-10 9:07
Groulien12-Apr-10 9:07 
AnswerRe: Multithreaded drawing Pin
Tarakeshwar Reddy12-Apr-10 9:37
professionalTarakeshwar Reddy12-Apr-10 9:37 
AnswerRe: Multithreaded drawing Pin
ntrceptr12-Apr-10 9:46
ntrceptr12-Apr-10 9:46 
AnswerRe: Multithreaded drawing Pin
William Winner12-Apr-10 10:16
William Winner12-Apr-10 10:16 
I can't say for sure what's causing it, but I was curious about something in your code:

C#
public void Commando(object obj)
{
     while (true)
     {
          Graphics x = this.CreateGraphics();
          x.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
          x.DrawLine(pen, new Point(0, 0),
                     new Point(
          MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y));

          this.Refresh();
     }
}


you set it up as a parameterized void, and you passed it true, but then you never actually check the object. obj does absolutely nothing in this example.

I don't think you're going to be able to get away from the flicker the way you're doing it.

Why, can't you just put the code into the MouseMove? It will flicker a tiny bit while you're moving, but when the mouse is stopped, no flicker.

C#
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    this.Refresh();
    Graphics x = this.CreateGraphics();
    x.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    x.DrawLine(pen, new Point(0, 0),
        new Point(
       MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y));
}


Oh, and I modified your code to be more thread friendly:
C#
public void Commando(object obj)
{
    while (true)
    {
        Graphics x = this.CreateGraphics();
        x.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        x.DrawLine(pen, new Point(0, 0),
            new Point(
           MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y));

        if (this.InvokeRequired)
        {
            RefreshMe = RefreshForm;
            this.Invoke(RefreshMe);
        }

    }
}

private delegate void RefreshFormDel();

private RefreshFormDel RefreshMe;

private void RefreshForm()
{
    this.Refresh();
}


private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    if (t != null)
        if (t.IsAlive)
            t.Abort();
}

QuestionUser and Password Prompt Pin
Jassim Rahma12-Apr-10 5:59
Jassim Rahma12-Apr-10 5:59 
AnswerRe: User and Password Prompt Pin
Dave Kreskowiak12-Apr-10 6:14
mveDave Kreskowiak12-Apr-10 6:14 
GeneralRe: User and Password Prompt Pin
Jassim Rahma12-Apr-10 6:28
Jassim Rahma12-Apr-10 6:28 
GeneralRe: User and Password Prompt Pin
J4amieC12-Apr-10 6:35
J4amieC12-Apr-10 6:35 
AnswerRe: User and Password Prompt Pin
Ravi Bhavnani12-Apr-10 19:17
professionalRavi Bhavnani12-Apr-10 19:17 
QuestionWebBrowser Control - .NET 3.5 - C# Pin
Jon Braunsma12-Apr-10 4:58
Jon Braunsma12-Apr-10 4:58 
AnswerRe: WebBrowser Control - .NET 3.5 - C# Pin
Not Active12-Apr-10 5:26
mentorNot Active12-Apr-10 5:26 
AnswerRe: WebBrowser Control - .NET 3.5 - C# Pin
itsravie12-Apr-10 5:46
itsravie12-Apr-10 5:46 
AnswerRe: WebBrowser Control - .NET 3.5 - C# Pin
Jon Braunsma12-Apr-10 9:40
Jon Braunsma12-Apr-10 9:40 
GeneralRe: WebBrowser Control - .NET 3.5 - C# Pin
Dave Kreskowiak12-Apr-10 9:55
mveDave Kreskowiak12-Apr-10 9:55 
Questionhow to get textbox value from one class to another Pin
Sr...Frank12-Apr-10 4:44
Sr...Frank12-Apr-10 4:44 
AnswerRe: how to get textbox value from one class to another Pin
ramzg12-Apr-10 5:13
ramzg12-Apr-10 5:13 
AnswerRe: how to get textbox value from one class to another Pin
DaveyM6912-Apr-10 14:55
professionalDaveyM6912-Apr-10 14:55 
Questionsql query Pin
engg_sukreet12-Apr-10 2:58
engg_sukreet12-Apr-10 2:58 
AnswerWrong Forum Pin
Keith Barrow12-Apr-10 3:04
professionalKeith Barrow12-Apr-10 3:04 
GeneralRe: Wrong Forum Pin
PIEBALDconsult12-Apr-10 4:02
mvePIEBALDconsult12-Apr-10 4:02 
AnswerRe: sql query Pin
PIEBALDconsult12-Apr-10 4:01
mvePIEBALDconsult12-Apr-10 4:01 

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.