|
thanx
|
|
|
|
|
|
thanx
|
|
|
|
|
Please don't cross post. Especially not in totally unreladed forums.
---
b { font-weight: normal; }
|
|
|
|
|
Can anybody tell me how to include the Style Builder dialog box
that is include in VS2005 in my own C# source code?
I wish to make my own Cascading Style sheets with
that nice Style Builder.
Thanks
Gywox
|
|
|
|
|
Hi,
A few weeks back i was trying to implement backgroundworker. I got a good code sample but i still didn't managed to get it to work.
I messed up my whole code. Nothing was working anymore. So i had to work on my backupped project. Now i got it back as how it was again.
I was kinda hoping if someone could help me again with it. Some comments would be really appreciated (in plain English).
This is my whole class:
public partial class FrmWordDisplayer : Form
{
public FrmWordDisplayer()
{
InitializeComponent();
this.FormClosing += new FormClosingEventHandler(FrmWordDisplayer_FormClosing);
}
private void FrmWordDisplayer_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult result = MessageBox.Show("wanna close?", "Conformation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
e.Cancel = false;
this.Dispose();
}
else if (result == DialogResult.No)
{
e.Cancel = true;
}
}
public void DisplayWord()
{
Show();
FileStream smallWords = File.Open(@"smallwords.txt", FileMode.Open, FileAccess.Read);
StreamReader rdr = new StreamReader(smallWords);
Random rnd = new Random();
string sDocument = rdr.ReadToEnd();
rdr.Close();
smallWords.Close();
string[] words = sDocument.Replace('\r', ' ').Replace('\n', ' ').Split(';');
while(true)
{
int numberChosen = rnd.Next(0, words.Length - 1);
this.lblDisplayWord.Text = words[numberChosen].ToString();
this.lblDisplayWord.Update();
Application.DoEvents();
Thread.Sleep(1000);
}
}
}
This is a second Form in my project. On my fist Form i got a few buttons. One of them, represents this Form. When this button is pressed, it execute this method: public void DisplayWord() and keeps displaying words until the user closes the Form.
But the Form still hangs. Thats why i want to implement the backgroundworker. It makes it possible the be in control of the Form the whole time.
Its this peace of code that makes the Form running slow and hang:
while(true)
{
int numberChosen = rnd.Next(0, words.Length - 1);
this.lblDisplayWord.Text = words[numberChosen].ToString();
this.lblDisplayWord.Update();
Application.DoEvents();
Thread.Sleep(1000);
}
Thanks in advance!
|
|
|
|
|
The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running. When you want a responsive UI and you are faced with long delays associated with such operations, the BackgroundWorker class provides a convenient solution.
To execute a time-consuming operation in the background, create a BackgroundWorker and listen for events that report the progress of your operation and signal when your operation is finished. You can create the BackgroundWorker programmatically or you can drag it onto your form from the Components tab of the Toolbox. If you create the BackgroundWorker in the Windows Forms Designer, it will appear in the Component Tray, and its properties will be displayed in the Properties window.
To set up for a background operation, add an event handler for the DoWork event. Call your time-consuming operation in this event handler. To start the operation, call RunWorkerAsync. To receive notifications of progress updates, handle the ProgressChanged event. To receive a notification when the operation is completed, handle the RunWorkerCompleted event.
I can not see BackroundWorker.RunAsync() method in your code, you must trigger your background worker with this method. In MSDN there are useful examples.
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Drawing;<br />
using System.Threading;<br />
using System.Windows.Forms;<br />
<br />
namespace BackgroundWorkerExample<br />
{ <br />
public class FibonacciForm : System.Windows.Forms.Form<br />
{ <br />
private int numberToCompute = 0;<br />
private int highestPercentageReached = 0;<br />
<br />
private System.Windows.Forms.NumericUpDown numericUpDown1;<br />
private System.Windows.Forms.Button startAsyncButton;<br />
private System.Windows.Forms.Button cancelAsyncButton;<br />
private System.Windows.Forms.ProgressBar progressBar1;<br />
private System.Windows.Forms.Label resultLabel;<br />
private System.ComponentModel.BackgroundWorker backgroundWorker1;<br />
<br />
public FibonacciForm()<br />
{ <br />
InitializeComponent();<br />
<br />
InitializeBackgoundWorker();<br />
}<br />
<br />
private void InitializeBackgoundWorker()<br />
{<br />
backgroundWorker1.DoWork += <br />
new DoWorkEventHandler(backgroundWorker1_DoWork);<br />
backgroundWorker1.RunWorkerCompleted += <br />
new RunWorkerCompletedEventHandler(<br />
backgroundWorker1_RunWorkerCompleted);<br />
backgroundWorker1.ProgressChanged += <br />
new ProgressChangedEventHandler(<br />
backgroundWorker1_ProgressChanged);<br />
}<br />
<br />
private void startAsyncButton_Click(System.Object sender, <br />
System.EventArgs e)<br />
{<br />
resultLabel.Text = String.Empty;<br />
<br />
this.numericUpDown1.Enabled = false;<br />
<br />
this.startAsyncButton.Enabled = false;<br />
<br />
this.cancelAsyncButton.Enabled = true;<br />
<br />
numberToCompute = (int)numericUpDown1.Value;<br />
<br />
highestPercentageReached = 0;<br />
<br />
backgroundWorker1.RunWorkerAsync(numberToCompute);<br />
}<br />
<br />
private void cancelAsyncButton_Click(System.Object sender, <br />
System.EventArgs e)<br />
{ <br />
this.backgroundWorker1.CancelAsync();<br />
<br />
cancelAsyncButton.Enabled = false;<br />
}<br />
<br />
private void backgroundWorker1_DoWork(object sender, <br />
DoWorkEventArgs e)<br />
{ <br />
BackgroundWorker worker = sender as BackgroundWorker;<br />
<br />
e.Result = ComputeFibonacci((int)e.Argument, worker, e);<br />
}<br />
<br />
private void backgroundWorker1_RunWorkerCompleted(<br />
object sender, RunWorkerCompletedEventArgs e)<br />
{<br />
if (e.Error != null)<br />
{<br />
MessageBox.Show(e.Error.Message);<br />
}<br />
else if (e.Cancelled)<br />
{<br />
resultLabel.Text = "Canceled";<br />
}<br />
else<br />
{<br />
resultLabel.Text = e.Result.ToString();<br />
}<br />
<br />
this.numericUpDown1.Enabled = true;<br />
<br />
startAsyncButton.Enabled = true;<br />
<br />
cancelAsyncButton.Enabled = false;<br />
}<br />
<br />
private void backgroundWorker1_ProgressChanged(object sender,<br />
ProgressChangedEventArgs e)<br />
{<br />
this.progressBar1.Value = e.ProgressPercentage;<br />
}<br />
<br />
long ComputeFibonacci(int n, BackgroundWorker worker, DoWorkEventArgs e)<br />
{<br />
if ((n < 0) || (n > 91))<br />
{<br />
throw new ArgumentException(<br />
"value must be >= 0 and <= 91", "n");<br />
}<br />
<br />
long result = 0;<br />
<br />
<br />
if (worker.CancellationPending)<br />
{ <br />
e.Cancel = true;<br />
}<br />
else<br />
{ <br />
if (n < 2)<br />
{ <br />
result = 1;<br />
}<br />
else<br />
{ <br />
result = ComputeFibonacci(n - 1, worker, e) + <br />
ComputeFibonacci(n - 2, worker, e);<br />
}<br />
<br />
int percentComplete = <br />
(int)((float)n / (float)numberToCompute * 100);<br />
if (percentComplete > highestPercentageReached)<br />
{<br />
highestPercentageReached = percentComplete;<br />
worker.ReportProgress(percentComplete);<br />
}<br />
}<br />
<br />
return result;<br />
}<br />
<br />
<br />
#region Windows Form Designer generated code<br />
<br />
private void InitializeComponent()<br />
{<br />
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();<br />
this.startAsyncButton = new System.Windows.Forms.Button();<br />
this.cancelAsyncButton = new System.Windows.Forms.Button();<br />
this.resultLabel = new System.Windows.Forms.Label();<br />
this.progressBar1 = new System.Windows.Forms.ProgressBar();<br />
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();<br />
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();<br />
this.SuspendLayout();<br />
this.numericUpDown1.Location = new System.Drawing.Point(16, 16);<br />
this.numericUpDown1.Maximum = new System.Decimal(new int[] {<br />
91,<br />
0,<br />
0,<br />
0});<br />
this.numericUpDown1.Minimum = new System.Decimal(new int[] {<br />
1,<br />
0,<br />
0,<br />
0});<br />
this.numericUpDown1.Name = "numericUpDown1";<br />
this.numericUpDown1.Size = new System.Drawing.Size(80, 20);<br />
this.numericUpDown1.TabIndex = 0;<br />
this.numericUpDown1.Value = new System.Decimal(new int[] {<br />
1,<br />
0,<br />
0,<br />
0});<br />
this.startAsyncButton.Location = new System.Drawing.Point(16, 72);<br />
this.startAsyncButton.Name = "startAsyncButton";<br />
this.startAsyncButton.Size = new System.Drawing.Size(120, 23);<br />
this.startAsyncButton.TabIndex = 1;<br />
this.startAsyncButton.Text = "Start Async";<br />
this.startAsyncButton.Click += new System.EventHandler(this.startAsyncButton_Click);<br />
this.cancelAsyncButton.Enabled = false;<br />
this.cancelAsyncButton.Location = new System.Drawing.Point(153, 72);<br />
this.cancelAsyncButton.Name = "cancelAsyncButton";<br />
this.cancelAsyncButton.Size = new System.Drawing.Size(119, 23);<br />
this.cancelAsyncButton.TabIndex = 2;<br />
this.cancelAsyncButton.Text = "Cancel Async";<br />
this.cancelAsyncButton.Click += new System.EventHandler(this.cancelAsyncButton_Click);<br />
this.resultLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;<br />
this.resultLabel.Location = new System.Drawing.Point(112, 16);<br />
this.resultLabel.Name = "resultLabel";<br />
this.resultLabel.Size = new System.Drawing.Size(160, 23);<br />
this.resultLabel.TabIndex = 3;<br />
this.resultLabel.Text = "(no result)";<br />
this.resultLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;<br />
this.progressBar1.Location = new System.Drawing.Point(18, 48);<br />
this.progressBar1.Name = "progressBar1";<br />
this.progressBar1.Size = new System.Drawing.Size(256, 8);<br />
this.progressBar1.Step = 2;<br />
this.progressBar1.TabIndex = 4;<br />
this.backgroundWorker1.WorkerReportsProgress = true;<br />
this.backgroundWorker1.WorkerSupportsCancellation = true;<br />
this.ClientSize = new System.Drawing.Size(292, 118);<br />
this.Controls.Add(this.progressBar1);<br />
this.Controls.Add(this.resultLabel);<br />
this.Controls.Add(this.cancelAsyncButton);<br />
this.Controls.Add(this.startAsyncButton);<br />
this.Controls.Add(this.numericUpDown1);<br />
this.Name = "FibonacciForm";<br />
this.Text = "Fibonacci Calculator";<br />
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.Run(new FibonacciForm());<br />
}<br />
}<br />
}
|
|
|
|
|
Hi mertkan65,
Thank you for your reply!
I've read those examples many times. Its too complicated.
I was hoping if someone could help me implement it in my code.
I tried many things with no success...
|
|
|
|
|
It looks to me like you would be better off just using a timer. But, maybe you are doing an exercise in multithreading. In which case, it doesn't look like you've created a separate thread anywhere.
Something like this might be closer to what you are trying to do:
public partial class frmWordDisplayer : Form
{
private Thread tMyThread;
delegate void SetlabelCallback(string cCaption);
public frmWordDisplayer()
{
InitializeComponent();
this.FormClosing += new FormClosingEventHandler(FrmWordDisplayer_FormClosing);
}
private void FrmWordDisplayer_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult result = MessageBox.Show("wanna close?","Conformation", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
e.Cancel = false;
tMyThread.Abort();
this.Dispose();
}
else if (result == DialogResult.No)
{
e.Cancel = true;
}
}
public void DisplayWord()
{
Show();
tMyThread = new Thread(new ThreadStart(DisplayWordThread));
tMyThread.Start();
}
private void DisplayWordThread()
{
FileStream smallWords = File.Open(@"smallwords.txt", FileMode.Open, FileAccess.Read);
StreamReader rdr = new StreamReader(smallWords);
Random rnd = new Random();
string sDocument = rdr.ReadToEnd();
rdr.Close();
smallWords.Close();
string[] words = sDocument.Replace('\r', ' ').Replace('\n', ' ').Split(';');
while(true)
{
int numberChosen = rnd.Next(0, words.Length - 1);
SetLabelCaption(words[numberChosen].ToString());
Thread.Sleep(1000);
}
}
private void SetLabelCaption(String cCaption)
{
if (this.lblDisplayWord.InvokeRequired)
{
SetlabelCallback d = new SetlabelCallback(SetLabelCaption);
this.Invoke(d, new object[] { cCaption });
}
else
{
this.lblDisplayWord.Text = cCaption;
this.lblDisplayWord.Update();
}
}
}
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Hi EricDV,
Thank you for your reply!
I was using the Application.DoEvents() method to be able to keep control over the Form in my while statement.
But it still the tendency to "hang". So i've been told to use the backgroundworker which makes the user able to have control over the Form all the time.
I did want to use the multi thread too, but i've been advised not to do so.
Also i really want to learn this backgroundworker, sounds like a very usefull "thing".
If there is any one that could help me with backgroundworker, i'll be very gratefull!
Thanks in advance!
|
|
|
|
|
My BackgroundWorker experience is not so much but as I understood from MSDN, your code implemeantation is wrong.
I think instead of "Application.DoEvents()" you can use "FormClosing.RunAsync()" method where you want your BW to start. For instance you can put this method in the other Form constructor. Calling "FormClosing.RunAsync()" starts your thread, thread will stop when it finishes its job or when you wants to stopped it. Since I dont know your whole code, I cant give exact code examples.
|
|
|
|
|
can somebody give me the source code of this problem (TSP travelling salesman problem) in java ?? or somewhere similar ???
please ???
|
|
|
|
|
You have to be kidding. Do you own homework. By the way, this is a C# message board, not java.
|
|
|
|
|
if you have a specific problem with your code, ask and we will help. But don't just ask for the entire code.
|
|
|
|
|
Dear Sir or Madam,
I need an implementation of one of the applications of parallel cellular automata, like graph coloring, fire forest, encryption,...
Looking forward to hearing from you,
Thanks in advance,
|
|
|
|
|
If anybody have dump for, Exam 70–536: TS: Microsoft .NET Framework 2.0 - Application Development Foundation, pls provide me the zip file.
Thanks in advance
kumar
|
|
|
|
|
Whats the use of getting certified after reading the dumps. You will not get thru the interviews if you dont answer questions having shown your certified, it will straight away prove that you passed your exam using dumps and you dont know anything about the technology.
Take your time, probably a month for each paper. The internet has a lot of free materials/articles/forums to help you understand the stuff.
Tarakeshwar
MCP, CCIE Q(R&S)
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes.
!sgub evah t'nseod margorp sihT ?sgub naem ayaddahW
|
|
|
|
|
I already have some experience in the .Net, i just want to know the pattern of the questions so that i can be focused.
|
|
|
|
|
hi kumar,
as per my knowledge, u will find the Eaxm papers(those are 90% accurate) in braindumps.com
good Luck for ur certification
Rahi
|
|
|
|
|
Hi,
I'm using an embedded usercontrol in a web form to be able to drag files from the windows explorer. I handel the dragdrop event with the following code
private void UserControl1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
string[] files = (string[])e.Data.GetData( DataFormats.FileDrop, true );
foreach( string file in files )
{
// do something
}
}
The problem is that theres always just one file. If i use the control on a ordinary windows form i get all the files i drag onto the control.
I'm thankful for any advice.
|
|
|
|
|
Hi,
Can any one help me in changing the attribute value of a property outside the class .
eg
class First
{
[readonly(true)]
Class1 {get{return child;}set{child =value;}}
}
class Second
{
(change class1 readonly value)
}
for this eg if property Class1 has readonly attribute can i change that value in class second .
Thank you
regards
Praveen
|
|
|
|
|
How can u change its value and it is a READONLY???>>>
Its type is a READONLY and in english words read only means only for reading not for changing
Jamil Abou Khalil
|
|
|
|
|
readonly value change means
[readonly(true)]or[readonly(false)]
Here True or flase is the value.
|
|
|
|
|
create object of class first
first f = new first();
f.readonly = true;(according to your need)
if you want to access it without making its object then make it static
or use delegates
It is Good to be Important but!
it is more Important to be Good
|
|
|
|
|
The attribute determines how the code is compiled. You can't change that at run time.
---
b { font-weight: normal; }
|
|
|
|
|