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

  • 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. – Steven Burnap Oct 10 '14 at 15:29
  • 1
    possible duplicate of When profiling a function for time use, what information is desirable? – user53019 Oct 10 '14 at 15:38
  • 2
    We don't need the details of TelephonyServer here. – Frank Hileman Oct 10 '14 at 16:16
5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.