Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my code,</p> <pre><code>public class ValueReader { List&lt;IDataReader&gt; _list = new List&lt;IDataReader&gt;(); object _criticalSection = new object(); public ValueReader() { //Nothign here } public void Attach(IDataReader reader) { lock(_criticalSection) { _list.Add(reader); } } public void Detach(IDataReader reader) { lock(_criticalSection) { _list.Remove(reader); } } public void Notify(string value) { lock(_criticalSection) { foreach(IDataReader reader in _list) { reader.Update(value); } } } public void Start() { new Thread(new ThreadStart(Run)).Start(); } private void Run() { while(true) { //generate value Notify(value); Thread.Sleep(5000); } } } public interface IDataReader { void UpdateControls(string value); } public class FirstClass : IDataReader { .... ...... ValueReader _reader = null; public FirstClass() { _reader = new ValueReader(); _reader.Start(); _reader.Attach(this); } private void AddToSmartClient() { // _reader has added to SmartClient's WorkItem } private delegate void UpdateControlDelegate(string value); public void UpdateControl(string value) { if(txtAddress.InvokeRequired) { txtAddress.Invoke(new UpdateControlDelegate(UpdateControl), value); } else { txtAddress.Text = value; txtValue.Text = value; } } } public class SecondClass : IDataReader { .... ...... ValueReader _reader = null; public void SecondClass() { _reader = ReadFromSmartClient(); _reader.Attach(this); } private ValueReader ReadFromSmartClient() { reader = //Get from SmartClient's Workitem. return reader } private delegate void UpdateControlDelegate(string value); public void UpdateControl(string value) { if(InvokeRequired) { BeginInvoke(new UpdateControlDelegate(UpdateControl), value); } else { control1.Text = value; control2.Text = value; } } } </code></pre> <p>I invokes only FirstClass for some time. In this case its working fine. After some time i invoked the Second class, at this time while calling Attach from secondClass the application is hanging.(i monitered that its comming until Attach methods's lock(_criticalSection).</p> <p>After some time i converter the Update control in the Frist Class as follow</p> <pre><code> public void UpdateControl(string value) { if(InvokeRequired) { BeginInvoke(new UpdateControlDelegate(UpdateControl), value); } else { txtAddress.Text = value; txtValue.Text = value; } } </code></pre> <p>This is working well after invoking the SecondClass also. Why its happening?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload