|
The Web Browser control is designed to run in a Single threaded fashion.
You can not use multi threading when using Web Broswer Control.
BTW, why do you need a seperate thread for this? You can use a timer instead.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi,
your situation is not clear to me.
if you have two Application.Run() statements, I think you are on the wrong track.
If the first form is just a splash screen, I know you are doing it wrong.
A splash screen does not need an Application.Run, just create one and Show() it.
Then do Application.Run(new Form2());
And make sure your static main() is decorated with a [STAThread]
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
My apologies for not explaining my situation clearly.
It is a small client application, the first form is a login form which shows the user a dropdown list which they select an account name from.
Then I wish to pass this account name to the main form.
It has been awhile since i have done any work with multi-threading but you cant just use form.Show() can you?
I just tried and the form shows and then closes straight away.
As far as I was aware if you are using multiple forms, you needed to use Application.Run()?
Please correct me if I am wrong.
|
|
|
|
|
Abydosgater wrote: if you are using multiple forms, you needed to use Application.Run()?
wrong.
A Windows app that has modeless forms needs a single Application.Run, so you get one message pump.
Abydosgater wrote: use form.Show()
right.
form.Show() will show the form until the user closes it, the app closes it or the app exits.
it is wise to keep the form's reference alive though.
Remember: A single message pump can serve multiple modeless forms (i.e. those shown by calling Show).
Abydosgater wrote: multi-threading
haven't seen your reasons for even considering multi-threading.(there is no need AFAIK).
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Ah I see.
Well when i use form.Show() it shows the form and closes it straight away. It doesnt give the user a chance to select an account.
I have tried form.ShowDialog() and that seems to keep the form active.
LoginForm loginForm = new LoginForm();<br />
loginForm.ShowDialog();
I then added OpenMainForm(string accountname) to the Program class:
<br />
public static void OpenMainForm(string accountname)<br />
{ Application.Run(new MainForm(accountname)); }
So when the program launches it shows the login form, and then when the user selects an account it calls the static OpenMainForm in the Program Class which uses Application.Run(), but thats gives errors.
Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead.
Considering the invalid methods I have been using, would it be more logical for me to launch the main form with Application.Run(), have it hidden and show the login form as a dialog from within the main form?
Andy
|
|
|
|
|
Hi,
I suggest you study this example:
public class Form2 : Form {
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new Form2("a").Show();
new Form2("b").Show();
Application.Run(new Form2("c"));
}
public Form2(string title) {
Text=title;
}
}
Find out the difference between those forms.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Ah thank you, I see where my mistake is. form.Show() only works if you have Application.Run on another form.
ie:
new Form2("b").Show();<br />
Application.Run(new Form2("c"));
Thank you very much =]
|
|
|
|
|
Abydosgater wrote: form.Show() only works if you have Application.Run on another form.
Not quite.
new Form2("b").Show();
new Form2("c").Show();
Application.Run();
also works, but behaves slightly differently.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi guys, I'm trying to just update a progress bar in a simple app that downloads files.
The relevent code is as follows:
static void updateProgress(object sender, DownloadProgressChangedEventArgs e)
{
progress = e.ProgressPercentage;
}
static void finishedDownload(object sender, AsyncCompletedEventArgs e)
{
done = true;
progress = 0;
(sender as IDisposable).Dispose();
}
public void downloadFile(string url)
{
done = false;
progress = 0;
WebClient client = new WebClient();
try
{
client.DownloadFileCompleted += new AsyncCompletedEventHandler(finishedDownload);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(updateProgress);
Console.WriteLine("Before");
client.DownloadFileAsync(new Uri(url), Application.StartupPath + "\\temp.flv");
Console.WriteLine("After");
}
catch (Exception ex)
{
if (client != null)
client.Dispose();
done = true;
MessageBox.Show(ex.Message);
}
}
So the problem is that updateProgress() and finishedDownload() don't get called when client.DownloadFileAsync() completes and/or updates.
What am I doing wrong?
Thanks
-Fudge
|
|
|
|
|
Fudge Mutator wrote: client.DownloadFileCompleted += new AsyncCompletedEventHandler(finishedDownload); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(updateProgress);
Theere is no event attached to DownloadFileAsync
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Oh, forgot Form1.DoEvents() thanks!
|
|
|
|
|
Hi,
your code works for me. I added log statements to both event handlers, and got the file I asked for.
Nevertheless I would be inclined to make client a class member, so it cannot get collected as soon as downloadFile() returns.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi all,
I'm working in a project in which I need to import a text file containing a stream of comma delimited lines of data and convert it into a Microsoft Excel 2007 file in order to perform some queries on the Excel file and give some results.
When I wrote a code doing this, it took a very long execution time because the text file contains about 70,000 lines and I had to loop over all these lines, read each line, get the data in between the commas, then write it into the Excel file.
Then I knew that there is a built-in Microsoft Excel function called (Text to columns) in the (Data) menu which is doing the same job in a few seconds only.
The Question is : is there any way to import this Excel (Text to columns) function or use it into my C# code so that the user of my program doesn't have to open the text file in Microsoft Excel and convert the data into columns before using my program ?
Thanks.
|
|
|
|
|
hello sir ,
i am using a datagrid control in window form. my problem is that my data grid contain 24 columns. so is there any way i can disable scrolling for
first two columns.
|
|
|
|
|
DataGrid or DataGridView?
in a DGV the DataGridViewColumn.Frozen property should help you out.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
actually i am using datagrid
|
|
|
|
|
That is too bad, maybe you can switch to DGV?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
hello,
can anybody tell me how to change font of tooltip control ? because my project display in other langauge. it is not English ...
|
|
|
|
|
You will need to have the tooltip text either in the resource files or database(whatever you are using) and set it from there. May be this will help you:
SetToolTip(controlName,textfromResourceFile)
जय हिंद
|
|
|
|
|
i have retriev that text from my database. but it still cannot show. just show ាសថសដថាសដថាសដ something like this. so how can i do next ?
|
|
|
|
|
I don't seem to understand your problem. Can you re-phrase?
जय हिंद
|
|
|
|
|
ok. i have a tooltip control. and i want to change it font to other language. and i don found this tooltip's font property. it alway show as "ាសដថាសដ" when mouse on. and i also follow ur step that get text from Database. but i still cannót show in other language else from English after i get into tooltip control. so do u kno how to do with it ?
|
|
|
|
|
Whats the problem with "ាសដថាសដ"? It does not looks English to me.
जय हिंद
|
|
|
|
|
ាកសដកថis kind of other langauge that i want to show in tooltip control. it isnot a English langauge. understand ? it is just a data that i retrieved from database as a step that u have told me.
|
|
|
|
|
If you have retrieved this text from database, just set this as the text for the tooltip. If it does not shows up correct, I think you need to look into encoding.
By the way, which language is this?
जय हिंद
|
|
|
|