Click here to Skip to main content
15,892,072 members
Home / Discussions / C#
   

C#

 
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
mve#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
mve#realJSOP1-Feb-10 10:51 
GeneralRe: Adding and removing differences from List compared to another list Pin
zagitta1-Feb-10 11:29
zagitta1-Feb-10 11:29 
GeneralRe: Adding and removing differences from List compared to another list Pin
#realJSOP1-Feb-10 23:20
mve#realJSOP1-Feb-10 23:20 
GeneralRe: Adding and removing differences from List compared to another list Pin
zagitta2-Feb-10 2:55
zagitta2-Feb-10 2:55 
GeneralRe: Adding and removing differences from List compared to another list Pin
Dan Mos2-Feb-10 7:36
Dan Mos2-Feb-10 7:36 
GeneralRe: Adding and removing differences from List compared to another list [modified] Pin
zagitta3-Feb-10 4:37
zagitta3-Feb-10 4:37 
GeneralRe: Adding and removing differences from List compared to another list Pin
Luc Pattyn1-Feb-10 12:15
sitebuilderLuc Pattyn1-Feb-10 12:15 
GeneralRe: Adding and removing differences from List compared to another list Pin
#realJSOP1-Feb-10 23:22
mve#realJSOP1-Feb-10 23:22 
Questionsql instances and a deuced connection Pin
reza assar1-Feb-10 10:27
reza assar1-Feb-10 10:27 
AnswerRe: sql instances and a deuced connection Pin
Rutvik Dave1-Feb-10 10:39
professionalRutvik Dave1-Feb-10 10:39 
QuestionC1Flexgrid datetime picker background color Pin
Member 13252301-Feb-10 10:26
Member 13252301-Feb-10 10:26 

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.