in

Archived Data Techniques Forums

How can I show a fax status on a text box with VB.NET?

Last post 04-21-2010 12:57 PM by brianb. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 04-16-2010 6:18 AM

    • KC
    • Top 10 Contributor
    • Joined on 06-26-2004
    • Posts 57

    How can I show a fax status on a text box with VB.NET?

    I try use a windows form's text box to display the fax status but it was not allowed. Any idea?

    Private Sub faxman_status(ByVal sender As Object, ByVal args As DataTech.FaxManNet.FaxEventArgs) Handles faxman.FaxStatus

    Label1.Text = args.Fax.Port.ToString

    Label2.Text = args.Fax.FaxStatus.ToString

    End Sub

     

    Regards,

  • 04-16-2010 1:57 PM In reply to

    • brianb
    • Top 10 Contributor
    • Joined on 09-29-2009
    • Burnsville, NC
    • Posts 58

    Re: How can I show a fax status on a text box with VB.NET?

    Please define "not allowed".  I'm not sure what you mean by that.

    Brian
    Technical Support
    Data Techniques
    Support Options

    Knowledgebase

    Forums
    Filed under:
  • 04-19-2010 10:19 PM In reply to

    • KC
    • Top 10 Contributor
    • Joined on 06-26-2004
    • Posts 57

    Re: How can I show a fax status on a text box with VB.NET?

    I got an error when it running at the above SUB. You may try to set a simple program to test. Regard, KC
  • 04-21-2010 12:57 PM In reply to

    • brianb
    • Top 10 Contributor
    • Joined on 09-29-2009
    • Burnsville, NC
    • Posts 58

    Re: How can I show a fax status on a text box with VB.NET?

    Most likely you are getting an InvalidOperation exception which is actually being thrown because of an inner exception with the following message: 

    Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on.

    The FaxStatus event fires from a background thread and therefore, being on a separate thread from the user interface, cannot be used to update the controsl on the UI.  This is something we may correct in future releases of FaxMan SDK.  But for now here's a workaround:

    1. Modify the FaxStatus event to use BeginInvoke:

             Private Sub faxMan1_FaxStatus(ByVal sender As Object, ByVal args As DataTech.FaxManNet.FaxEventArgs)
                frmModemStatus.UpdateStatus(args.Fax)

                If InvokeRequired Then
                    Dim aArray(1) As Object
                    aArray(0) = args.Fax.Port.ToString()
                    aArray(1) = args.Fax.FaxStatus.ToString()
                    BeginInvoke(New MyDelegate(AddressOf UpdateStatusDisplay), aArray)
                End If

                Try
                    TextBox1.Text = args.Fax.Port.ToString()
                    TextBox2.Text = args.Fax.FaxStatus.ToString()
                Catch ex As Exception
                    System.Diagnostics.Debug.WriteLine("ex = " & ex.ToString())
                End Try

            End Sub

     2. Define a new delegate:

             Delegate Sub MyDelegate(ByVal faxPort As String, ByVal faxStatus As String)

     3. Create the callback method referenced in the BeginInvoke method:

            Private Sub UpdateStatusDisplay(ByVal faxPort As String, ByVal faxStatus As String)
                TextBox1.Text = faxPort
                TextBox2.Text = faxStatus
            End Sub



    Brian
    Technical Support
    Data Techniques
    Support Options

    Knowledgebase

    Forums
Page 1 of 1 (4 items)
Copyright 2009 Data Techniques, Inc. All Rights Reserved.