المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Multithreaded drawing



C# Programming
04-12-2010, 10:10 PM
The line in my form is flickering.
The form is DoubleBuffered which made me kind of lost http://www.barakasoft.com/script/Forums/Images/smiley_WTF.gif .

Help?

using System;
using System.Windows.Forms;
using System.Threading;
using System.Drawing.Design;

namespace Threading
{
public partial class Form1 : Form
{
Pen pen = new Pen(Color.Black);

//I have an event that aborts the thread when closing the form.
Thread t;
public Form1()
{
InitializeComponent();

pen.Width = 3;
pen.StartCap = System.Drawing.Drawing2D.LineCap.SquareAnchor;
pen.EndCap = System.Drawing.Drawing2D.LineCap.RoundAnchor;
//I used a ParameterizedThreadStart for debugging but I grew none the wiser.
t = new Thread(new ParameterizedThreadStart(Commando));
t.Start(true);
}
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.********.X, MousePosition.Y - this.********.Y));

this.*******();
}
}
}
}

Any help is appreciated.