473,396 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Thread blocking diagnosis

Bob
Hi,
I have an app that has a 3rd party phone answering control (4 of )
(interfacing with dialogic 4 line card) attached to the main form.
each control raises an event when its Dialogic line detects ring tone.
I use the ring detect event handler to create a new thread which is given a
reference to the control that is being rung. The called method then
interacts with the control until the call finishes.
My problem is that I believe I am getting thread blocking between the
threads that are dealing with the calls.
There doesn't appear to be any consistent pattern to the blocking and I was
wondering what techniques I can use to further investigate this. I have run
the app under a commercial profiler but there is nothing definitive showing.
Each of the phone call threads seem to get roughly the same time.
The blocking occurs when the phone handling objects are getting input from
phone users. (DTMF tones) but varies at which point it occurs.

Initiating Code from one of the four ring detect event handlers follows:
telecall te = new telecall();//Class that contains state engine to handle
call

te.TraceMessage += new telecall.TraceMessageEventHandler(te_TraceMessage) ;//
info back from state engine

te.LineStateChange += new
telecall.LineStateChangeEventHandler(this.SetLineS tatus); // Phone line
status back from state engine

te.MyForm = this;//Ref to stop orphans

te.Vbocx = ((AxVbocxLibrary.AxVBocx)(sender));//Assigning ref to the line
handling object.

ThreadStart ts = new ThreadStart(te.HandleCall);// State engine

Thread t = new Thread(ts);

t.Name = "PH1";

t.SetApartmentState(ApartmentState.STA);//desperation

t.Start();
Oct 10 '06 #1
3 3274

Bob wrote:
Hi,
I have an app that has a 3rd party phone answering control (4 of )
(interfacing with dialogic 4 line card) attached to the main form.
each control raises an event when its Dialogic line detects ring tone.
I use the ring detect event handler to create a new thread which is given a
reference to the control that is being rung. The called method then
interacts with the control until the call finishes.
My problem is that I believe I am getting thread blocking between the
threads that are dealing with the calls.
There doesn't appear to be any consistent pattern to the blocking and I was
wondering what techniques I can use to further investigate this. I have run
the app under a commercial profiler but there is nothing definitive showing.
Each of the phone call threads seem to get roughly the same time.
The blocking occurs when the phone handling objects are getting input from
phone users. (DTMF tones) but varies at which point it occurs.

Initiating Code from one of the four ring detect event handlers follows:
telecall te = new telecall();//Class that contains state engine to handle
call

te.TraceMessage += new telecall.TraceMessageEventHandler(te_TraceMessage) ;//
info back from state engine

te.LineStateChange += new
telecall.LineStateChangeEventHandler(this.SetLineS tatus); // Phone line
status back from state engine

te.MyForm = this;//Ref to stop orphans

te.Vbocx = ((AxVbocxLibrary.AxVBocx)(sender));//Assigning ref to the line
handling object.

ThreadStart ts = new ThreadStart(te.HandleCall);// State engine

Thread t = new Thread(ts);

t.Name = "PH1";

t.SetApartmentState(ApartmentState.STA);//desperation

t.Start();
>From the COM library reference, it appears that you are using an older
version of CallSuite... Those are STA Com Objects, and as such each
one must exist on it's own thread or you need to use the async methods
methods provided by the control or they will block each other. One way
I have over come this, is to write a wrapper class for the VoiceBocx
object that spawns a thread in the constructor. that intializes the
object and then calls Application.Run. I use a ManualReset Event to
signal that intialization has completed. It is complex I guess, but it
works well. I use a newer version - 9.1, and I don't use the ActiveX
control - only the object, but this code was written with the older
version originally. The code here is not all of the code, nor is it
actually working code - it is just a bit to illustrate the point:

public sealed class Trunk : System.IDisposable
{
private ADXVoiceClass trunk;
private ManualResetEvent intialized;
private Exception startup;

public Trunk(int channel)
{
this.startup = null;

/ set this so that we can signal initilization...
this.intialized = new ManualResetEvent(false);

// VoiceBocx objects need to exist on their own thread to
// avoid blocking problems. So, we will create an STA Thread,
// create the object and start a message pump for the object.
Thread runner = new Thread (new ThreadStart(this.ObjectThread));
runner.ApartmentState = ApartmentState.STA;
runner.IsBackground = true;
runner.Start ();

// wait for intialization to complete.
this.intialized.WaitOne();
this.intialized.Close();
if (this.startup != null)
{
throw this.startup;
}
}

private void ObjectThread()
{
try
{
// set up the trunk object
InitializeTrunkObject();

// signal the parent!
this.intialized.Set();

// start a message loop for COM events on this thread
Application.Run();
}
catch (Exception ex)
{
this.startup = ex;
this.intialized.Set ();
}
}

..... Lots of other junk
}

The actual working code actually lets you pass in a value to determine
if it creates a thread for the object or not. I am not saying this is
the only (or even the best way), but if you want to use multiple phone
lines in your application, then you will need to use the async model
supported by the VoiceBocx control or arrange to have each line live on
it's own thread.

Anyway,
HTH

--
Tom Shelton

Oct 10 '06 #2

Tom Shelton wrote:
Bob wrote:
Hi,
I have an app that has a 3rd party phone answering control (4 of )
(interfacing with dialogic 4 line card) attached to the main form.
each control raises an event when its Dialogic line detects ring tone.
I use the ring detect event handler to create a new thread which is given a
reference to the control that is being rung. The called method then
interacts with the control until the call finishes.
My problem is that I believe I am getting thread blocking between the
threads that are dealing with the calls.
There doesn't appear to be any consistent pattern to the blocking and I was
wondering what techniques I can use to further investigate this. I have run
the app under a commercial profiler but there is nothing definitive showing.
Each of the phone call threads seem to get roughly the same time.
The blocking occurs when the phone handling objects are getting input from
phone users. (DTMF tones) but varies at which point it occurs.
By the way, if this is CallSuite - there is a bug in the GetDigits
call. It will always pause 3 seconds, even if you tell it to return
immediately. The only way around it that I have found is to implement
my own digit buffer using the DigitDetected event.

--
Tom Shelton

Oct 10 '06 #3
Bob
Hi Tom,
Thank you for the example,
Yes, using 5.2. The penny finally dropped that although I was spawing new
threads ultimately they were refering back to the 4 controls on the parent
form. I have taken a slightly more expensive way in that I now have a form
with only one control on it and I spawn 4 of these, hide them and have them
report back to the main form via events.
Load test today. (Heres hoping:-))
regards
Bob
"Tom Shelton" <to*@mtogden.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
>
Bob wrote:
Hi,
I have an app that has a 3rd party phone answering control (4 of )
(interfacing with dialogic 4 line card) attached to the main form.
each control raises an event when its Dialogic line detects ring tone.
I use the ring detect event handler to create a new thread which is
given a
reference to the control that is being rung. The called method then
interacts with the control until the call finishes.
My problem is that I believe I am getting thread blocking between the
threads that are dealing with the calls.
There doesn't appear to be any consistent pattern to the blocking and I
was
wondering what techniques I can use to further investigate this. I have
run
the app under a commercial profiler but there is nothing definitive
showing.
Each of the phone call threads seem to get roughly the same time.
The blocking occurs when the phone handling objects are getting input
from
phone users. (DTMF tones) but varies at which point it occurs.

Initiating Code from one of the four ring detect event handlers follows:
telecall te = new telecall();//Class that contains state engine to
handle
call

te.TraceMessage += new
telecall.TraceMessageEventHandler(te_TraceMessage) ;//
info back from state engine

te.LineStateChange += new
telecall.LineStateChangeEventHandler(this.SetLineS tatus); // Phone line
status back from state engine

te.MyForm = this;//Ref to stop orphans

te.Vbocx = ((AxVbocxLibrary.AxVBocx)(sender));//Assigning ref to the
line
handling object.

ThreadStart ts = new ThreadStart(te.HandleCall);// State engine

Thread t = new Thread(ts);

t.Name = "PH1";

t.SetApartmentState(ApartmentState.STA);//desperation

t.Start();
From the COM library reference, it appears that you are using an older
version of CallSuite... Those are STA Com Objects, and as such each
one must exist on it's own thread or you need to use the async methods
methods provided by the control or they will block each other. One way
I have over come this, is to write a wrapper class for the VoiceBocx
object that spawns a thread in the constructor. that intializes the
object and then calls Application.Run. I use a ManualReset Event to
signal that intialization has completed. It is complex I guess, but it
works well. I use a newer version - 9.1, and I don't use the ActiveX
control - only the object, but this code was written with the older
version originally. The code here is not all of the code, nor is it
actually working code - it is just a bit to illustrate the point:

public sealed class Trunk : System.IDisposable
{
private ADXVoiceClass trunk;
private ManualResetEvent intialized;
private Exception startup;

public Trunk(int channel)
{
this.startup = null;

/ set this so that we can signal initilization...
this.intialized = new ManualResetEvent(false);

// VoiceBocx objects need to exist on their own thread to
// avoid blocking problems. So, we will create an STA Thread,
// create the object and start a message pump for the object.
Thread runner = new Thread (new ThreadStart(this.ObjectThread));
runner.ApartmentState = ApartmentState.STA;
runner.IsBackground = true;
runner.Start ();

// wait for intialization to complete.
this.intialized.WaitOne();
this.intialized.Close();
if (this.startup != null)
{
throw this.startup;
}
}

private void ObjectThread()
{
try
{
// set up the trunk object
InitializeTrunkObject();

// signal the parent!
this.intialized.Set();

// start a message loop for COM events on this thread
Application.Run();
}
catch (Exception ex)
{
this.startup = ex;
this.intialized.Set ();
}
}

.... Lots of other junk
}

The actual working code actually lets you pass in a value to determine
if it creates a thread for the object or not. I am not saying this is
the only (or even the best way), but if you want to use multiple phone
lines in your application, then you will need to use the async model
supported by the VoiceBocx control or arrange to have each line live on
it's own thread.

Anyway,
HTH

--
Tom Shelton

Oct 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John P. Speno | last post by:
So you have this problem, and you decide to use threads to solve it... System is Python 2.3.3 on Solaris 9. I'm using the classic Python thread model. Main thread puts stuff into a...
3
by: David Sworder | last post by:
This message was already cross-posted to C# and ADO.NET, but I forgot to post to this "general" group... sorry about that. It just occured to me after my first post that the "general" group readers...
44
by: Charles Law | last post by:
Hi guys. I'm back on the threading gig again. It's the age-old question about waiting for something to happen without wasting time doing it. Take two threads: the main thread and a worker...
2
by: Bruce Vander Werf | last post by:
How can I cleanly stop a thread that is currently blocking on Socket.Receive? I don't want to use Thread.Abort, because I would like the thread method to exit cleanly, and the same code must run...
7
by: David Sworder | last post by:
Hi, I'm developing an application that will support several thousand simultaneous connections on the server-side. I'm trying to maximize throughput. The client (WinForms) and server communicate...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
6
by: Joe HM | last post by:
Hello - I have a function that calls Thread.Abort() to stop a thread in a _Closed() Method of a GUI. The thread contains a blocking call on a TCP socket and that is the easiest way to stop...
18
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do...
1
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
Sorry this is so long winded, but here goes. Following the model of http://msdn2.microsoft.com/en-us/library/system.runtime.remoting.channels.ipc.ipcchannel.aspx I made a remote object using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.