0

I have a telephony application, there is a windows service(third party product) running on a remote server. The application runs against the server. To connect the server, we have the code.

public static TelephonyServer ts;
ts = new TelephonyServer(sIpaddress, "username", "password");

TelephonyServer is very complicated.

After getting TelephonyServer instance, now we can get the resource from it in the application. Say:

 m_ChannelResource = m_TelephonyServer.GetChannel();
 m_VoiceResource = m_ChannelResource.VoiceResource; // VoiceResource

Remember each telephone call will have its own VoiceResource. Then in the code, I used a thread to make a call. If there are N calls, it will have N threads.

Now in each thread, we dial a number by Dial method then play a string by PlayTTS code.

public DialResult Dial(string phonenumber)
{
    int num = 1024;
    num += phonenumber.Length * 2;
    byte[] array = this.SerializePropertiesForInvocation();
    num += array.Length;
    VPacket vPacket = new VPacket(this.TelephonyLinkInfo.Guid, num, "ChannelResource.Dial.string.Invoke", 1);
    vPacket.WriteNullableString(phonenumber);
    vPacket.Serialize(array);
    vPacket.DoneWriting();
    byte[] buffer = base.TelephonyServer.ExecuteCommandHelperAsync(vPacket.Buffer, "ChannelResource::Dial()");
    vPacket = VPacket.FromByteArray(buffer, "ChannelResource.Dial.string.Reply");
    int version = vPacket.Version;
    if (version == 1)
    {
           this.DeSerializePropertiesFromReply(VPacket.FromByteArray((byte[])vPacket.Deserialize()));
        vPacket.DoneReading();
        return this.m_DialResult;
    }
    vPacket.DoneReading();
    throw new Exception("ChannelResource::Dial() Wrong Packet Version Received From Invocation.");
}

And.

public PlayTTS(string ttsString, string voice)
{
    int num = 1024;
    
    this.StopPlayAsync();
    if (ttsString != null && ttsString.Length > 0)
    {
        num += ttsString.Length * 2;
    }
    if (voice != null && voice.Length > 0)
    {
        num += voice.Length * 2;
    }
    byte[] array = this.SerializePropertiesForInvocation();
    num += array.Length;
    VPacket vPacket = new VPacket(this.TelephonyLinkInfo.Guid, num, "VoiceResource.PlayTTS.string.string.Invoke", 1);
    vPacket.WriteNullableString(ttsString);
    vPacket.WriteNullableString(voice);
    vPacket.Serialize(array);
    vPacket.DoneWriting();
    byte[] buffer = base.TelephonyServer.ExecuteCommandHelperAsync(vPacket.Buffer, "VoiceResource::PlayTTS()");
    vPacket = VPacket.FromByteArray(buffer, "VoiceResource.PlayTTS.string.string.Reply");
    int version = vPacket.Version;
    if (version == 1)
    {
        this.DeSerializePropertiesFromReply(VPacket.FromByteArray((byte[])vPacket.Deserialize()));
    vPacket.DoneReading();

    }
    vPacket.DoneReading();
    throw new Exception("VoiceResource::PlayTTS() Wrong Packet Version Received From Invocation.");
}

Now I have to face a question that using C# Task or async/await choice in my application. From this article, I heard that using Task or async/await is depend on whether the application is I/O bound or CPU bound.

I am not quite sure the application is I/O bound or CPU bound or some kind of hybrid. Can you give me some advice based on my information?

EDIT: Remove TelephonyServer detail image based on comment. 10/10/2014 12:54pm

Love
  • 233
  • 3
  • 9
  • open task manager and see if it takes up a full core – ratchet freak Oct 10 '14 at 15:19
  • No, the total cpu usuage is 3% now in my desktop. – Love Oct 10 '14 at 15:21
  • Modern CPUs run at the nanosecond level while network IO runs at the millisecond level. If a program whose primary purpose is to deal with the network is CPU bound, you are doing something very, very wrong. – Gort the Robot Oct 10 '14 at 15:29
  • 1
    possible duplicate of [When profiling a function for time use, what information is desirable?](http://programmers.stackexchange.com/questions/32504/when-profiling-a-function-for-time-use-what-information-is-desirable) –  Oct 10 '14 at 15:38
  • @GlenH7,perhaps not. I want a direct answer, IO bound or CPU bound. Please see http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Tip-2-Distinguish-CPU-Bound-work-from-IO-bound-work. I need to decide how to do async work in C#. – Love Oct 10 '14 at 15:51
  • 2
    We don't need the details of TelephonyServer here. – Frank Hileman Oct 10 '14 at 16:16
  • http://meta.stackexchange.com/a/194495/165773 – gnat Oct 10 '14 at 16:25
  • I'm confused by `ExecuteCommandHelperAsync`. The name suggests that it is asynchronous, but the usage looks completely synchronous. Which one is it? – svick Oct 10 '14 at 16:59
  • @svick, I don't know. I checked the dll, `ExecuteCommandHelperAsync` contains `AsyncWait`. And `public AsyncWait() { this.m_ThreadEvent = EventCache.GetMRE(); object syncVar; Monitor.Enter(syncVar = AsyncWait.SyncVar); try { AsyncWait.s_UniqueId++; this.m_UniqueId = AsyncWait.s_UniqueId; AsyncWait.s_AsyncThreads.Add(this.m_UniqueId, this);...` – Love Oct 10 '14 at 17:21

1 Answers1

6

The only portions of code that are CPU bound in a program are those that contain loops performing lots of calculations on large amounts of data. If you are not writing a game, graphics program, image processing program, or doing complex data analysis or modeling, you are unlikely to have CPU bound code. Any code that uses a network or file system to transfer data frequently is almost surely IO bound.

Frank Hileman
  • 3,922
  • 16
  • 18