GdPicture.NET Reference Guide
TwainGetState Method (GdPictureImaging)
Example 





GdPicture14 Namespace > GdPictureImaging Class : TwainGetState Method
Gets the recent TWAIN state of the currently executed TWAIN session.

The TWAIN protocol defines seven states that exist in the TWAIN session in order to ensure the session is executed correctly. For more details on TWAIN states, please refer to the TWAIN Specification.

Syntax
'Declaration
 
Public Function TwainGetState() As TwainStatus
public TwainStatus TwainGetState()
public function TwainGetState(): TwainStatus; 
public function TwainGetState() : TwainStatus;
public: TwainStatus TwainGetState(); 
public:
TwainStatus TwainGetState(); 

Return Value

A member of the TwainStatus enumeration. The current TWAIN state of the on-going TWAIN session.
Remarks
Be aware that this is not the error status of the last executed TWAIN operation. For further explanation please refer to the example below.

Just to inform you that you can try the TWAIN functionality using one of TWAIN demo projects available in your installation folder.

Example
How to get the current TWAIN state in the on-going TWAIN session.
Dim caption As String = "Example: TwainGetState"
Using oImage As GdPictureImaging = New GdPictureImaging()
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption)
    Dim result As Boolean = oImage.TwainSelectSource(Me.Handle)
    If Not result Then GoTo no_success
 
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption)
    result = oImage.TwainOpenDefaultSource(Me.Handle)
    If Not result Then GoTo no_success
 
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption)
    result = oImage.TwainShowSetupDialogSource(Me.Handle)
    If Not result Then GoTo no_success
 
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption)
    result = oImage.TwainCloseSource()
    If Not result Then GoTo no_success
 
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption)
    result = oImage.TwainCloseSourceManager(Me.Handle)
    If Not result Then GoTo no_success
 
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption)
no_success:
    If result Then
        MessageBox.Show("Success!", caption)
    Else
        MessageBox.Show("Error!" + vbCrLf + "result code: " + oImage.TwainGetLastResultCode() + vbCrLf +
                        "condition code: " + oImage.TwainGetLastConditionCode(), caption)
        End If
    End Using
string caption = "Example: TwainGetState";
using (GdPictureImaging oImage = new GdPictureImaging())
{
    //Starting the current session.
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption);
 
    //Selecting the device.
    bool result = oImage.TwainSelectSource(this.Handle);
    if (!result) goto no_success;
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption);
 
    //Opening the selected device.
    result = oImage.TwainOpenDefaultSource(this.Handle);
    if (!result) goto no_success;
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption);
 
    //Showing the user interface if supported.
    result = oImage.TwainShowSetupDialogSource(this.Handle);
    if (!result) goto no_success;
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption);
 
    //Closing the source.
    result = oImage.TwainCloseSource();
    if (!result) goto no_success;
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption);
 
    //Closing the source manager.
    result = oImage.TwainCloseSourceManager(this.Handle);
    if (!result) goto no_success;
 
    MessageBox.Show("Twain state: " + oImage.TwainGetState(), caption);
    //Ending the current session.
 
no_success:
    if (result)
        MessageBox.Show("Success!", caption);
    else
        MessageBox.Show("Error!\nresult code: " + oImage.TwainGetLastResultCode() +
                        "\ncondition code: " + oImage.TwainGetLastConditionCode(), caption);
}
See Also

Reference

GdPictureImaging Class
GdPictureImaging Members
TwainGetLastResultCode Method
TwainGetLastConditionCode Method
TwainSelectSource(Int32) Method
TwainOpenDefaultSource(Int32) Method
TwainCloseSource Method