-1

I am creating a windows application using 3rd party dll. They had given some predefined methods to use. There is a method SetTag() which is use to update a value. Now my work is to get data from tcp client and send to this method. My tcp part is working well, I had tested it. The problem is occurring at the time when I call SetTag(). It works well for a while but after some time, it's showing just-in-time debugger pop-up with exception

An unhandled exception has occurred in myproject.vshost.exe

I don't understand from where this exception is occurring.

Whenever I get data from tcp client, my UpdateValues() is called, which calls the third-party SetTag()

// valuesInArray is an object array which contain
// the data from tcp client after converted to object
UpdateValues(valuesInArray); 

and the method:

public void UpdateValues(object[] values)
{
    this.BeginUpdate();
    for (int i = 0; i < 9; i++)
    {
        this.SetTag(TagHandle[i], (values[i]), Quality.Good, FileTime.UtcNow);
    }
    this.EndUpdate(false);
}

I had created a simulator, where the data is not coming from tcp client, itis sending data in a timer tick event. In that case no error is occurring and the program runs smoothly. Can you suggest why this error is occurring using tcp client and how I get rid of it?

Ed Chapel
  • 6,842
  • 3
  • 30
  • 44
mahua22
  • 141
  • 1
  • 4
  • 12

2 Answers2

0

You haven't provided enough details to explain what the error is. However, your code will benefit from using a try {} catch {} to 'handle' the exception. The exception has the details you are looking for.

public void UpdateValues(

object[] values)
{
    this.BeginUpdate();
    for (int i = 0; i < 9; i++)
    {
        try
        {
            this.SetTag(TagHandle[i], (values[i]), Quality.Good, FileTime.UtcNow);
        }
        catch (Exception e)
        {
            // Log or print out the details
            Console.WriteLine("Error occurred setting the value.");
            Console.WriteLine(e);
        }
    }
    this.EndUpdate(false);
}

In this example, the exception message and stack trace are printed to the console. Look in this output for the cause of your exception.

Ed Chapel
  • 6,842
  • 3
  • 30
  • 44
0

In .NET 4 and later, you need to mark the containing method (UpdateValues) with HandleProcessCorruptedStateExceptionsAttribute and SecurityCriticalAttribute to catch some special exceptions such as AccessViolationException

Henrik
  • 23,186
  • 6
  • 42
  • 92