Click here to Skip to main content
15,918,808 members
Home / Discussions / C#
   

C#

 
Questiondoubt about collections. Pin
Kishor Boddu19-Feb-09 11:40
Kishor Boddu19-Feb-09 11:40 
AnswerRe: doubt about collections. Pin
Ennis Ray Lynch, Jr.19-Feb-09 12:30
Ennis Ray Lynch, Jr.19-Feb-09 12:30 
QuestionHow get html source code of WebPage? Pin
aleXXXka19-Feb-09 11:17
aleXXXka19-Feb-09 11:17 
AnswerRe: How get html source code of WebPage? Pin
Luc Pattyn19-Feb-09 11:31
sitebuilderLuc Pattyn19-Feb-09 11:31 
GeneralRe: How get html source code of WebPage? Pin
aleXXXka19-Feb-09 12:44
aleXXXka19-Feb-09 12:44 
GeneralRe: How get html source code of WebPage? Pin
vaghelabhavesh19-Feb-09 13:07
vaghelabhavesh19-Feb-09 13:07 
GeneralRe: How get html source code of WebPage? Pin
aleXXXka22-Feb-09 7:50
aleXXXka22-Feb-09 7:50 
Questionupdating a label from a thread in a different class Pin
liamderice19-Feb-09 10:59
liamderice19-Feb-09 10:59 
I'm learning c# and would love some help with an issue that I'm having. I've created a little app that copies some images from one place to another. I've just started playing with Threading and have moved the copy to a thread in a different class. My issue is with updating a label on the main form with the text of what I'm copying. Here's a quick snippet of my code...

FrmMain.cs
private void btnCopyImages_Click(object sender, System.EventArgs e)
{
  updateStatusLabel("Running...");

  GetInitialSettings();

  Thread CopyThread = new Thread(new ThreadStart(CopyImages));
  CopyThread.Start();

  updateStatusLabel("Done.");
}

private void CopyImages() {
  Files oFiles = new Files();
  oFiles.sMediaDir = txtMediaDir.Text;
  oFiles.sBuildDir = txtBuildDir.Text;
  oFiles.sMediaFoldersFilter = txtFilterMediaFolders.Text;
  oFiles.bIsBMW = bIsBMW;
  oFiles.GetFolders(txtMediaDir.Text);
  rchTxtBoxFoldersCopied.Text = rchTxtBoxFoldersCopied.Text + "\n\n" + oFiles.sFoldersCopied;
  oFiles = null;
}

public void updateStatusLabel(string sText) {
  lblStatus.Text = sText;
  lblStatus.Refresh();
}


files.cs
private void updateLabel(string sText) {
  FrmMain oFrmMain = new FrmMain();
  oFrmMain.updateStatusLabel(sText);
  oFrmMain = null;
}

public void GetFolders(string sDir) {
  try
  {
    string sBuildFolder = "";
    string[] folders = Directory.GetDirectories(sDir);
    bool bFilteredFolder = false;

    foreach(string folder in folders)
    {
      //Console.WriteLine(folder.ToString());

      if (sMediaFoldersFilter == "All")
      {
        bFilteredFolder = true;
      }
      else {
        string[] sFolderFilters = sMediaFoldersFilter.Split(new char[] {','});
        foreach (string filterFolder in sFolderFilters)
        {
          if (folder.IndexOf(filterFolder) > -1)
          {
            bFilteredFolder = true;
            break;
          }
        }
      }

      if (bFilteredFolder) {
        string sFolder = folder.Substring(folder.LastIndexOf("\\") + 1);

        switch (sFolder.ToLower())
        {
          case "colourized" :
              ...
              CopyFiles(folder,sBuildFolder);
              ...
            }
            break;
          case ...
            break;
          default:
            //Console.WriteLine("skip folder : " + folder.ToString());
            break;
        }
      }

      bFilteredFolder = false;

      GetFolders(folder);
    }
  }
  catch (Exception err) {
    sFoldersCopied = sFoldersCopied + "An error occured trying to read directories\n" + err.Message + "\n";
  }
}

private void CopyFiles(string sMediaDir, string sBuildDir) {
  try
  {
    string[] files = Directory.GetFiles(sMediaDir);
    foreach (string file in files)
    {
      //Console.WriteLine(file.ToString() + "::" + sBuildDir);

      updateLabel("copying : " + folder.ToString());

      string name = Path.GetFileName(file);
      string dest = Path.Combine(sBuildDir,name);
      File.Copy(file,dest,true);
    }
  }
  catch (Exception err) {
    sFoldersCopied = sFoldersCopied + "An error occured trying to copy files\n" + err.Message + "\n";
  }
}


Any help for a newbie would be much appreciated Smile | :) .
AnswerRe: updating a label from a thread in a different class Pin
DaveyM6919-Feb-09 11:12
professionalDaveyM6919-Feb-09 11:12 
GeneralRe: updating a label from a thread in a different class Pin
liamderice20-Feb-09 4:48
liamderice20-Feb-09 4:48 
GeneralRe: updating a label from a thread in a different class Pin
DaveyM6920-Feb-09 6:02
professionalDaveyM6920-Feb-09 6:02 
GeneralRe: updating a label from a thread in a different class Pin
liamderice20-Feb-09 9:50
liamderice20-Feb-09 9:50 
GeneralRe: updating a label from a thread in a different class Pin
DaveyM6920-Feb-09 10:06
professionalDaveyM6920-Feb-09 10:06 
GeneralRe: updating a label from a thread in a different class Pin
DaveyM6920-Feb-09 10:27
professionalDaveyM6920-Feb-09 10:27 
AnswerRe: updating a label from a thread in a different class Pin
yuxuanji19-Feb-09 15:01
yuxuanji19-Feb-09 15:01 
AnswerRe: updating a label from a thread in a different class Pin
Luc Pattyn19-Feb-09 15:54
sitebuilderLuc Pattyn19-Feb-09 15:54 
QuestionGeneric Control WinForms and Toolbox/Designer Pin
DaveyM6919-Feb-09 10:54
professionalDaveyM6919-Feb-09 10:54 
AnswerRe: Generic Control WinForms and Toolbox/Designer Pin
Luc Pattyn19-Feb-09 11:34
sitebuilderLuc Pattyn19-Feb-09 11:34 
GeneralRe: Generic Control WinForms and Toolbox/Designer Pin
DaveyM6919-Feb-09 11:44
professionalDaveyM6919-Feb-09 11:44 
AnswerRe: Generic Control WinForms and Toolbox/Designer Pin
Luc Pattyn19-Feb-09 11:56
sitebuilderLuc Pattyn19-Feb-09 11:56 
QuestionI need help whit my programme Pin
ZRF6919-Feb-09 10:43
ZRF6919-Feb-09 10:43 
AnswerRe: I need help whit my programme Pin
Deresen19-Feb-09 11:36
Deresen19-Feb-09 11:36 
AnswerRe: I need help whit my programme Pin
Mycroft Holmes19-Feb-09 13:49
professionalMycroft Holmes19-Feb-09 13:49 
AnswerRe: I need help whit my programme Pin
DaveyM6919-Feb-09 14:23
professionalDaveyM6919-Feb-09 14:23 
QuestionPlease help me with this simple C question Pin
meixiang619-Feb-09 10:00
meixiang619-Feb-09 10:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.