Click here to Skip to main content
15,915,019 members
Home / Discussions / C#
   

C#

 
Questiondownloading file. in response: "Content-Disposition: attachment; filename="file.gif"" Pin
hello_amigo1-Feb-10 15:46
hello_amigo1-Feb-10 15:46 
AnswerRe: downloading file. in response: "Content-Disposition: attachment; filename="file.gif"" Pin
Not Active1-Feb-10 16:17
mentorNot Active1-Feb-10 16:17 
QuestionDynamic Multiple Dropdown Lists using Access Database Pin
scorpio221-Feb-10 13:44
scorpio221-Feb-10 13:44 
AnswerCross post Pin
Not Active1-Feb-10 16:14
mentorNot Active1-Feb-10 16:14 
GeneralRe: Cross post Pin
scorpio222-Feb-10 1:33
scorpio222-Feb-10 1:33 
GeneralRe: Cross post Pin
Not Active2-Feb-10 1:56
mentorNot Active2-Feb-10 1:56 
GeneralRe: Cross post Pin
scorpio222-Feb-10 2:55
scorpio222-Feb-10 2:55 
QuestionOpen Source Project Pin
programmervb.netc++1-Feb-10 13:06
programmervb.netc++1-Feb-10 13:06 
AnswerRe: Open Source Project Pin
April Fans2-Feb-10 20:18
April Fans2-Feb-10 20:18 
GeneralRe: Open Source Project Pin
programmervb.netc++3-Feb-10 16:17
programmervb.netc++3-Feb-10 16:17 
QuestionSending AT commands to a v.92 USB modem Pin
saeidfarahi1-Feb-10 11:55
saeidfarahi1-Feb-10 11:55 
AnswerRe: Sending AT commands to a v.92 USB modem Pin
Luc Pattyn1-Feb-10 12:10
sitebuilderLuc Pattyn1-Feb-10 12:10 
AnswerRe: Sending AT commands to a v.92 USB modem Pin
PIEBALDconsult1-Feb-10 15:01
mvePIEBALDconsult1-Feb-10 15:01 
GeneralRe: Sending AT commands to a v.92 USB modem Pin
Luc Pattyn1-Feb-10 15:11
sitebuilderLuc Pattyn1-Feb-10 15:11 
Questionrandom in background [modified] Pin
Mark H Bishop1-Feb-10 11:21
Mark H Bishop1-Feb-10 11:21 
AnswerRe: random in background Pin
harold aptroot1-Feb-10 11:39
harold aptroot1-Feb-10 11:39 
AnswerRe: random in background Pin
Abhinav S1-Feb-10 11:43
Abhinav S1-Feb-10 11:43 
GeneralRe: random in background Pin
Mark H Bishop2-Feb-10 4:05
Mark H Bishop2-Feb-10 4:05 
Thanks,

I have the code block tag understood now. It really is more readable. Sorry.

I have tried instantiation of one Random instance as a class member in the button click event that starts the BackGroundWorkers. I place the instant creation just before the loop that creates the BGWs. When I use this approach the application either returns a set of results containing blocks of zeros mixed with blocks of identical times or it hangs.

Random rand;

private void button1_Click(object sender, EventArgs e)
{
      rand=new Random();
      for (int i = 1; i <= 40; i++)
   {
      BackgroundWorker Computation = new BackgroundWorker();
      Computation.DoWork += new DoWorkEventHandler(Computation_DoWork);
      Computation.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Computation_RunWorkerCompleted);
      Computation.RunWorkerAsync();
   }
}

private double timeOccurance2(string target)
{
   string trial = string.Empty;
   double intialTime = DateTime.Now.ToOADate();
   int targetLength = target.Length;

   while (trial != target)
   {
       StringBuilder b = new StringBuilder();
       char[] ch = new char[target.Length];
       for (int i = 0; i < target.Length; i++)
      {
         ch[i] = Convert.ToChar(Convert.ToInt32(Math.Floor(10 * rand.NextDouble() + 48)));
      }

      for (int i = 0; i < target.Length; i++)
      {
         b.Append(ch[i].ToString());
      }

      trial = b.ToString();
   }

   double finalTime = DateTime.Now.ToOADate();
   return 24 * 60 * 60 * (finalTime - intialTime);
}

private void Computation_DoWork(object sender, DoWorkEventArgs e)
{
   e.Result = timeOccurance2("124456").ToString();
}

private void Computation_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
   richTextBox1.Text += (string)(e.Result);
   richTextBox1.Text += (char)(10);
}

AnswerRe: random in background Pin
Luc Pattyn1-Feb-10 12:11
sitebuilderLuc Pattyn1-Feb-10 12:11 
Questionhow to expose an event in user control Pin
nuttynibbles1-Feb-10 10:37
nuttynibbles1-Feb-10 10:37 
AnswerRe: how to expose an event in user control Pin
#realJSOP1-Feb-10 10:47
professional#realJSOP1-Feb-10 10:47 
AnswerRe: how to expose an event in user control Pin
DaveyM691-Feb-10 12:10
professionalDaveyM691-Feb-10 12:10 
GeneralRe: how to expose an event in user control Pin
nuttynibbles1-Feb-10 16:51
nuttynibbles1-Feb-10 16:51 
QuestionAdding and removing differences from List compared to another list Pin
zagitta1-Feb-10 10:34
zagitta1-Feb-10 10:34 
AnswerRe: Adding and removing differences from List compared to another list Pin
#realJSOP1-Feb-10 10:51
professional#realJSOP1-Feb-10 10:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.