|
Ofcourse I know Mark knows it.
I just thought that this poor guy may have no info at al about CP. by the kind of question he asked, I guess it must be his first time or second... I had a similar impression when i came to CP for the first time. It took me a while to start loving it. and today, i have more than 10-12 rss feeds of different forums.
|
|
|
|
|
Hi guy.
C is the programming language. Visual C is the developing tools of Microsoft, person uses the VC to make the C program.
|
|
|
|
|
Hello!
I am trying to understand more about threading but i can't find how to 'free' the UI from the threads working in the background. How can i use my form's controls or move/resize the window while a progressbar is updated from a loop in another thread?
Here is the code:
delegate void _delegate();
private void button1_Click(object sender, EventArgs e)
{
Thread t1 = new Thread(new ThreadStart(ProgressUpdate));
t1.Start();
}
void ProgressUpdate()
{
if (progressBar1.InvokeRequired)
{
progressBar1.Invoke(new _delegate(Progress));
}
else
{
for (int i = 1; i <= 100; i++)
{
progressBar1.Value = (i * 100) / 100;
Thread.Sleep(50);
}
}
}
void Progress()
{
for (int i = 1; i <= 100; i++)
{
progressBar1.Value = i;
Thread.Sleep(50);
}
}
|
|
|
|
|
you got it wrong.
Having Control.InvokeRequired and Control.Invoke the way you did is just fine, however they cause the else block in ProgressUpdate to execute on the GUI thread (that was the intention all along), so that else block should NOT contain lengthy operations nor calls to Thread.Sleep
You should perform all timing by:
- using timers;
- OR using whatever you like on YOUR threads;
- but not by using Thread.Sleep on the GUI thread.
So a better approach would be to have the thread execute some method, say Progress, which contains any delay you like, and calls ProgressUpdate (the new one without any Sleep) to update the GUI.
|
|
|
|
|
The easiest way to multithread in a WinForms application is by using a BackgroundWorker. With it, you don't need to worry about InvokeRequired and Control.Invoke, it takes care of this for you. You can get more details on the MSDN website (http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^]) , but below is a simple example.
private void button1_Click(object sender, EventArgs e)
{
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.WorkerSupportsCancellation = true;
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerAsync();
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else if (e.Cancelled)
{
}
else
{
}
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = (BackgroundWorker)sender;
for (int i = 1; i <= 100; i++)
{
if (!worker.CancellationPending)
{
Thread.Sleep(50);
worker.ReportProgress(i);
}
else
{
e.Cancel = true;
break;
}
}
}
|
|
|
|
|
|
Dears
I want to develop an application that reads news from XML file and displays this news in a popup (just like MSN popup).
I know how to make a popup window and I know everything in the software except:
1-How I feel that the XML file is updated to go to fetch and display the update only.
2-How I can read the news I need from the XML file and display only the lines I need to display.
Please reply to me and help me on this ASAP
|
|
|
|
|
Sherif W. Girgis wrote: help me on this ASAP
This is a very rude. We all contribute here voluntarily on our own time, not yours.
You have described a basic RSS reader. Look it up, ASAP
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
I use mapwindow in my project in c#.net. And so i will have different vector or raster layers added to it.
Apart from that i will draw some shapes in it.
Finally i have to save the file in some format for the transmission.
So if am the sender, then the receiver must be able to reproduce the data that i sent in some format.
I was suggested to use xml.
But i dont know how exactly it works with this appln. Can someone guide me to have a start up pls...
|
|
|
|
|
|
How can i embedd a flash movie my form in mono .net
I do it in windows platform but I can't do in linux
Can you help me
|
|
|
|
|
Well, you probably used some kind of control for that. Whoever made this control may also offer a version for Linux / Mono. Else you must look for a similar control from another source.
Developing such a control yourself is possible, but also a considerable amount of work. If you really want to go that far, you should get the specifications from Adobe first and see what options you have. There may be some kind of API which you may use in your control (then you are in luck), else you must basically implement a Flash player from scratch according to the specifications.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
yes I use a component when runing i take an error like this:
Unhandled Exception: System.NotImplementedException: COM/ActiveX support is not implemented
at System.Windows.Forms.AxHost.get_CreateParams () [0x00000] in /usr/src/packages/BUILD/mono-2.6.3/mcs/class/Managed.Windows.Forms/System.Windows.Forms/AxHost.cs:406
|
|
|
|
|
This means the component you are using isn't compatible with Mono as it uses some Windows specific things (such as COM). Not much you can do about it unless it's open source and you fancy doing a rewrite.
|
|
|
|
|
voice recognition source code using matlab or any suitable language
|
|
|
|
|
Well, quite.
Regards,
Rob Philpott.
|
|
|
|
|
NO.
This is not a "give me source code" site.
If you have a specific problem, ask and we will try to help.
Don't just demand source code because you are too lazy to either research it, or to do the work. It is rude, and unlikely to get you anywhere.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Where?
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Good question
|
|
|
|
|
Hello to All,
How can i add custom color in ColorDialog.
Thanks
If you can think then I Can.
|
|
|
|
|
you mean red color for example
EASY COME EASY GO
|
|
|
|
|
No, ColorDialog box have a option of Custom Color. In these boxes we can add our selected color.It may be red or according to R,G,B.
If you can think then I Can.
|
|
|
|
|
If it has the option, then what is your problem? Just turn the option on!
Or is there more to your query?
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
No Dear this option is only in GUI. my question is that is any option by using programmingly i can add custom color in Colordialog box.
If you can think then I Can.
|
|
|
|
|
Have you tried this?
ColorDialog cd = new ColorDialog();
cd.CustomColors = new int[] {1, 2000, 20000, 255, 255 * 0x100, 255 * 0x10000};
cd.ShowDialog();
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|