|
Good guess!
|
|
|
|
|
I need to access multiple accounts on a website, and have them all open at the same time. I assume I need to do this using threads. Furthermore later while running my program I need to be able to pick and choose which thread I am accessing to send or receive information from the site. I wish to use the same form while doing so.
How would I go about doing the above and can someone point me to a good example.
I appreciate any help,
Thanks in advance,
Michael
|
|
|
|
|
You probably need a form similar to most modern web browsers, where it has multiple tabs each accessing different accounts. You need to look at the System.Windows.Forms.WebBrowser [^] class and/or the System.Net [^] namespace for helper classes, especially HttpWebRequest [^] and HttpWebResponse [^]. As far as multi-threading goes you can find lots of samples via Google.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I have a winform where I dropped Backgroundworker control and running some loop in DoWork event handle. At the same time I am also within DoWork, I am calling "ReportProgress" method to update my ProgressBar. I thought as my work is going on within DoWork, I can click on other areas of Form and basically since its BackgroundWorker, my other GUI should be responsive but my whole Machine is frozen till "DoWork" finishes. What I am doing wrong? Here is code from :
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
ArgumentClass backGroundCls = e.Argument as ArgumentClass;
int ctr=0;
do
{
ctr++;
backgroundWorker1.ReportProgress(ctr);
} while (ctr < 10000000);
Favourite quote:
In youth we learn, In age we understand.
|
|
|
|
|
You may have separated the actual work into the background thread (Though I don't see this doing anything but incrementing a counter), but your ReportProgress calls themselves can lock up the GUI.
Each time you ReportProgress, you're sending a message from the background thread to the GUI thread, which locks up the GUI thread for a tiny fraction of a second. If you're CONSTANTLY doing that, you'll find the GUI becomes locked up entirely.
Try to reduce the frequency with which you send status updates... Maybe only send an update every X iterations, and do some testing to figure out a good value for X.
And I assume you're planning on having the background worker do more than count, because that's really going to slow things down
|
|
|
|
|
|
Wonderful..Works great by this..Thanks to all others
Favourite quote:
In youth we learn, In age we understand.
|
|
|
|
|
As Ian has said above, you are updating your progress too often.
Progress is normally a percentage, so between 0 and 100. You are counting to 10million so you probably only need to report every 10000 iterations.
Also, if there is nothing else happening, the UI probably won't have time to update fully even then - if it hasn't got time to update then your users certainly won't have time to see it so the update is pointless!
|
|
|
|
|
Even when using the Background worker, I advice to make use of BeginInvoke methods to update the user interface elements. This has worked for me big time.
Create appropriate delegates for user interface updates and invoke them as and when necessary.
Sunil
|
|
|
|
|
Sunil,
In what way it has helped you more? Can you share your thoughts more please?
Favourite quote:
In youth we learn, In age we understand.
|
|
|
|
|
Hey munishk,
I had developed and application that created approximate of 20 Background workers. All these workers had to update progressbars embedded in a listview for around 20 listview items. However, initially the DoWork event handler used to update the UI which made the UI very sloppy and was sometimes showing a hung behavior. I changed the implementation to make use of Delegates to update the UI and by calling the BeginInvoke method this issue got resolved.
void delegate UpdateProgressDelegate(object params);
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
ArgumentClass backGroundCls = e.Argument as ArgumentClass;
int ctr=0;
do
{
ctr++;
UpdateProgressDelegate del = new UpdateProgressDelegate(UpdateProgress);
del.BeginInvoke(ctr, null, null);
} while (ctr < 10000000);
}
private void UpdateProgress(int ctr)
{
}
This should definitely work and solve your issue.
Sunil
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Testing_Trig
{
class Program
{
static void Main(string[] args)
{
Double Radian = (Math.PI / 180);
Double count = 0;
int[] array = {1,0};
for (int i = 0; i < 2; i++)
{
if (array[i] == 1) count += Math.Tan(Radian);
if (array[i] == 0) count += Math.Tan(-Radian);
}
Console.WriteLine("count = {0}", count);
}
}
}
|
|
|
|
|
Welcome to the world of floating point numbers and imprecise trigonometric approximations. I think it must be the latter that's responsible for this one, as the sign bit shouldn't affect how a floating point number gets rounded.
That said, I ran an equivalent of this and it seems to give 0 for me.
|
|
|
|
|
I don't understand why your compiler give "0" and mine gives -4. Explain why?
|
|
|
|
|
Can you tell which compiler your using and version number? This is really a blow to me. I never thought this could happen.
Thanks
|
|
|
|
|
I'm using Win 7 64 bit and I'm using an interpreted language running on .Net 2.0 or 3.5 (the core libraries are the same):
$Environment:Version
2.0.50727.4971
|
|
|
|
|
It doesn't give you -4. -4.06575814682064E-20 is shorthand for -4.06575814682064 x 10^-20, that's -0.0000000000000000000406575814682064, which is pretty close to 0.
|
|
|
|
|
How can I get the program to show me "0" instead of -4.06575814682064E-20? Thank You.
|
|
|
|
|
Generally with floating point checking for exact equality is a bad idea. You probably want to check if the result is within a certain distance from 0 instead, the exact amount depends on the precision you need. As for the output, you can format it[^] to display the way you want it to.
|
|
|
|
|
Exactly.
This is not a C# problem. This is a floating-point "deficiency", although the usefulness of such a tiny fraction may be nil.
Here are documents from a few other languages that may help illustrate the issue to the OP. I particularly recommend the Python one, which one can understand without knowing anything at all about Python.
Python: Python manual[^]
Perl: Perl Cookbook[^]
|
|
|
|
|
Look at the number again and note that it's in scientific notation.
You didn't get -4.something. You got -0.00000000000000000004, which is pretty close to 0.
|
|
|
|
|
|
Look again, that's -4 x 10^-20. That's extremely close to 0.
|
|
|
|
|
C&P gives me 0 on VS 2010 / Windows 7 x64.
|
|
|
|
|
Hi,
I have procedure which returns huge xml data in ref cursor from Oracle procedure,
When the procedure is executed in Toad, it works fine, But when my method calls the procedure it returns an empty row in the datatable.
any help would be appreciated.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|