Thread.start doesn't work?

Plumm sailormoontw at gmail.com
Thu Jul 31 17:50:13 PDT 2008


The code is as follows: 
The problem is if some exception happens, it should open up a messagebox(messagebox works without being inside a thread), and I haven't tested the code without the DWT environment, but I think it might be the Tango problem, not the DWT problem. This code works if it's not in a thread though.

and there is a thread.start() right after the Thread definition. Note : text_file_input, text_file_output, button_convert, and thread are all declared as static scope.

           thread = new Thread(
           {
             int int_lines = 0;
             FileConduit file_input  = null;
             FileConduit file_output = null;
             DataOutput  file_out    = null;
             
             try
             {
               file_input  = new FileConduit (text_file_input.getText());
               file_output = new FileConduit (text_file_output.getText(), FileConduit.WriteCreate);
               file_out    = new DataOutput (file_output);

               foreach (str_line; new LineInput(file_input))
               {
                 int_lines++;
             
                 int int_last_index = 0;
                 foreach ( int_index, int_item ; int_idn_locations)
                 {
                   int int_item1 = int_item -1 ;
                 
                   if (int_item1 + 10 > str_line.length)
                     break;
               
                   if ((int_item1 != 0) && (int_last_index != int_item1))
                     file_out.write (str_line[int_last_index..int_item1]);
                   
                   if (str_line[int_item1..int_item1+10] != "          ")
                     file_out.write(cjidn_encode(str_line[int_item1..int_item1+10]));
                   else
                     file_out.write(cast(char[])("          "));
                   
                   int_last_index = int_item1 + 10;
                 }
                 file_out.write(str_line[int_last_index..length]);
                 file_out.write("\r\n");
                 
                 Thread.sleep(0.001);
               }
               
               auto sprint0 = new Sprint!(char);
               MessageBox messageBox0 = new MessageBox(DWT.OK|DWT.ICON_INFORMATION);
               messageBox0.setText("Done");
               messageBox0.setMessage(sprint0("{} Lines", int_lines));
               messageBox0.open();
             }
             catch (Exception o)
             {
               auto sprint = new Sprint!(char);
               MessageBox messageBox = new MessageBox(DWT.OK|DWT.ICON_ERROR);
               messageBox.setText("Error");
               messageBox.setMessage(sprint("Error : {}", o.msg));
               messageBox.open();
             }
             finally
             {
               if (!(file_out is null))
                 file_out.flush();
               if (!(file_output is null))
                 file_output.close();
               if (!(file_input is null))
                 file_input.close();
               button_convert.setEnabled(true);
             }
           });


More information about the Digitalmars-d-dwt mailing list