Click here to Skip to main content
16,005,222 members
Home / Discussions / C#
   

C#

 
GeneralRe: Switch Behavior in C# Pin
Mycroft Holmes16-Nov-08 15:39
professionalMycroft Holmes16-Nov-08 15:39 
GeneralRe: Switch Behavior in C# Pin
Mark Churchill16-Nov-08 16:01
Mark Churchill16-Nov-08 16:01 
GeneralRe: Switch Behavior in C# Pin
Mycroft Holmes16-Nov-08 17:19
professionalMycroft Holmes16-Nov-08 17:19 
GeneralRe: Switch Behavior in C# Pin
Mark Churchill16-Nov-08 17:32
Mark Churchill16-Nov-08 17:32 
Questioncomparing two datasets Pin
Melanie Booysen15-Nov-08 19:48
Melanie Booysen15-Nov-08 19:48 
AnswerRe: comparing two datasets Pin
Dave Kreskowiak16-Nov-08 4:58
mveDave Kreskowiak16-Nov-08 4:58 
QuestionTrusted & Digitially signed Files Pin
123pips15-Nov-08 10:00
123pips15-Nov-08 10:00 
QuestionTheadPool hanhs in release Pin
baranils15-Nov-08 6:33
baranils15-Nov-08 6:33 
Hello

I still have some problems understanding Threads

In the following example, I'm calling a method in a new thread from a form I'm using ThreadPool

The method contains two event to update a datagridview in the calling form

In debug mode it runs perfectly
In release it hangs randomly during the called process

It never reach the end

Any idea
Many thanks for your attention



Calling Code :
..
      DistMatrix dm = new DistMatrix();
      dm.VV = VV;
      dm.AddRow += new DistMatrix.StepRowDelegateHandler(Dist_StepRow);
      dm.AddCell += new DistMatrix.StepCellDelegateHandler(Dist_StepCell);
      ThreadPool.QueueUserWorkItem(new WaitCallback(Process),dm);
    }
 
    public delegate void StepCellDelegateHandler(int a, int b);
    public delegate void StepRowDelegateHandler(DataTable dt);
 
    // *****************************************************************************************
    void Process(Object DM)
    {
      DataTable dtn = ((DistMatrix)DM).getMatrix(dtAdr);
    }
 
    // *****************************************************************************************
    private void Dist_StepCell(int a, int b)
    {
      if (this.InvokeRequired)
      {
        try
        {
          this.Invoke(new StepCellDelegateHandler(StepCell), new object[] { a, b });
          return;
        }
        catch (Exception e)
        {
          MessageBox.Show(e.Message);
        }
      }
      else
      {
        this.StepCell(a, b);
      }
    }


Treatment

// ***********************************************************************************
  public DataTable getMatrix(DataTable dtIn)
  {
    DataTable dtMatrix=CreateTable(dtIn);
    for (i = 0; i < dtIn.Rows.Count; i++)
    {
      DataRow cRowY = dtIn.Rows[i];
      string fromY = cRowY["addrId"].ToString();

      for (j = 0; j < dtIn.Rows.Count; j++)
      {
        DataRow cRowX = dtIn.Rows[j];
        addDtCell(dtMatrix,cRowX["addrId"].ToString(),fromY,5);
        if (AddCell != null)
        {
          AddCell(j,i);
        }
      }
    }

    if (AddRow != null)
    {
      AddRow(dtMatrix);
    }

    if (AddCell != null)
    {
      AddCell(-1, -1);
    }

    return dtMatrix;
  }
  // ***********************************************************************************
  private void addDtCell(DataTable DstMatrix, string rX, string rY, double dist)
  {
    DataView dv = new DataView(DstMatrix);
    dv.Sort = "Start";
    int idx = dv.Find(rY);
    DataRow cRow = null;
    if (idx < 0)
    {
      cRow = DstMatrix.Rows.Add();
      cRow["Start"] = rY;
      if (AddRow != null)
      {
        AddRow(DstMatrix);
      }
    }
    else
    {
      cRow = dv[idx].Row;
    }
    if (dist > 0.01)
    {
      cRow[rX] = dist;
    }
  }

Questiona password riddle Pin
nelsonpaixao15-Nov-08 5:54
nelsonpaixao15-Nov-08 5:54 
RantRe: a password riddle Pin
Vimalsoft(Pty) Ltd15-Nov-08 5:59
professionalVimalsoft(Pty) Ltd15-Nov-08 5:59 
GeneralRe: a password riddle Pin
Paul Conrad15-Nov-08 6:00
professionalPaul Conrad15-Nov-08 6:00 
GeneralRe: a password riddle Pin
Pete O'Hanlon15-Nov-08 11:07
mvePete O'Hanlon15-Nov-08 11:07 
AnswerRe: a password riddle Pin
Paul Conrad15-Nov-08 5:59
professionalPaul Conrad15-Nov-08 5:59 
GeneralRe: a password riddle Pin
Guffa15-Nov-08 14:13
Guffa15-Nov-08 14:13 
GeneralRe: a password riddle Pin
nelsonpaixao16-Nov-08 13:09
nelsonpaixao16-Nov-08 13:09 
GeneralRe: a password riddle Pin
Russell Jones17-Nov-08 0:32
Russell Jones17-Nov-08 0:32 
Questionc# Reflection Pin
koleraba15-Nov-08 5:19
koleraba15-Nov-08 5:19 
AnswerRe: c# Reflection Pin
S. Senthil Kumar15-Nov-08 19:19
S. Senthil Kumar15-Nov-08 19:19 
QuestionChat or IRC Pin
duta15-Nov-08 2:01
duta15-Nov-08 2:01 
AnswerRe: Chat or IRC Pin
EliottA15-Nov-08 5:49
EliottA15-Nov-08 5:49 
QuestionSafeHandle.SetOwnership(false) Pin
HosamAly15-Nov-08 1:47
HosamAly15-Nov-08 1:47 
QuestionRe: SafeHandle.SetOwnership(false) Pin
HosamAly15-Nov-08 3:13
HosamAly15-Nov-08 3:13 
GeneralRe: SafeHandle.SetOwnership(false) Pin
HosamAly15-Nov-08 3:32
HosamAly15-Nov-08 3:32 
QuestionREQ: C# Ordinary Kriging Interpolation implementation Pin
MavKilla15-Nov-08 1:19
MavKilla15-Nov-08 1:19 
AnswerRe: REQ: C# Ordinary Kriging Interpolation implementation Pin
annukar18-May-11 10:24
annukar18-May-11 10:24 

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.