I have the code below for scanning but When i press the button to start scanning, the windows form freezes and i can not move the form or minimizie/colse it until the process will be finished! i'm new in working with Thread but i tried to add Thread andi couldn't solve the problem. Does anyone know to where (how) can i write a Thread to release my form from freezing? Thanks.
public Bitmap GetBitmapFromRawData(int w, int h, byte[] data)
{
   //Do sth
 }
    //button to start the scan proccess
    private void button1_Click(object sender, EventArgs e)
    {
      try
      {
        var deviceManager = new DeviceManager();
        for ( int i = 1; i <= deviceManager.DeviceInfos.Count; i++ ) 
        {
          if ( deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType ) 
          {
            continue;
          }
          lstListOfScanner.Items.Add(deviceManager.DeviceInfos[i].Properties["Name"].get_Value());
        }
      }
      catch ( COMException ex )
      {
        MessageBox.Show(ex.Message);
      }
      try
      {
        var deviceManager = new DeviceManager();
        DeviceInfo AvailableScanner = null;
        for ( int i = 1; i <= deviceManager.DeviceInfos.Count; i++ ) 
        {
          if ( deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType ) // Skip device If it is not a scanner
          {
            continue;
          }
          AvailableScanner = deviceManager.DeviceInfos[i];
          break;
        }
        var device = AvailableScanner.Connect(); 
        var ScanerItem = device.Items[1];
        var imgFile = (ImageFile)ScanerItem.Transfer();
        var data = (byte[])imgFile.FileData.get_BinaryData();
        var bitmap = GetBitmapFromRawData(imgFile.Width, imgFile.Height, data);
        var Path = @"C:\....\ScanImg.jpg"; 
        bitmap.Save(Path, ImageFormat.Jpeg);
      }
      catch ( COMException ex )
      {
        MessageBox.Show(ex.Message);
      }
 
    