Click here to Skip to main content
15,913,467 members
Home / Discussions / C#
   

C#

 
QuestionGet method name as string Pin
Nicholas Butler29-Jul-08 23:36
sitebuilderNicholas Butler29-Jul-08 23:36 
AnswerRe: Get method name as string Pin
leppie30-Jul-08 0:22
leppie30-Jul-08 0:22 
GeneralRe: Get method name as string Pin
Nicholas Butler30-Jul-08 0:36
sitebuilderNicholas Butler30-Jul-08 0:36 
AnswerRe: Get method name as string Pin
DaveyM6930-Jul-08 1:09
professionalDaveyM6930-Jul-08 1:09 
GeneralRe: Get method name as string Pin
leppie30-Jul-08 2:27
leppie30-Jul-08 2:27 
QuestionControl.Invoke() equivalent with Thread object Pin
ccufi29-Jul-08 23:36
ccufi29-Jul-08 23:36 
AnswerRe: Control.Invoke() equivalent with Thread object Pin
Frank Horn30-Jul-08 0:36
Frank Horn30-Jul-08 0:36 
AnswerRe: Control.Invoke() equivalent with Thread object Pin
Alan N30-Jul-08 4:55
Alan N30-Jul-08 4:55 
Hello,
Useful classes are the System.ComponentModel AsyncOperationManager and AsyncOperation. I've pasted in some code that performs a directory search in a background thread. When complete the background thread raises on event on the thread that called BeginSearch.

This calling thread does not need to consider the source of the event and may use the information received in the EventArgs directly in any control.

Alan.

/* DirectorySearch.cs
 *
 * Purpose : Directory data collection on a background thread
 *
 * Revision History
 * Based on Microsoft.Samples.DirectorySearcher but simplified and
 * modified to use ThreadPool, AsyncOperationManager
 */
using System;
using System.ComponentModel;
using System.Threading;
using System.IO;

namespace SpecTest {
  class DirectorySearchCP {
    private AsyncOperation operation;
    private String startDir;
    private DirectoryInfo[] dirlist;
    public event EventHandler<DirListEventArgs> SearchComplete;

    // Create the search thread, which will initiate the search.
    public void BeginSearch(String startDir) {
      this.startDir = startDir;
      operation = AsyncOperationManager.CreateOperation(null);
      ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProcedure), null);
    }
    
    private void SearchDirectory() {
      DirectoryInfo s = new DirectoryInfo(startDir);
      dirlist = s.GetDirectories("*.*", SearchOption.TopDirectoryOnly);
    }

    // This method runs in a background thread to collect directory information.
    private void ThreadProcedure(Object stateInfo) {
      try {
        SearchDirectory();
      } finally {
        // Raise an event to notify the user that the search has terminated. 
        // This event is raised on the thread that called BeginSearch
        operation.PostOperationCompleted(new SendOrPostCallback(OnSearchComplete), dirlist);
      }
    }

    private void OnSearchComplete(Object state) {
      EventHandler<DirListEventArgs> handler = SearchComplete;
      if (handler != null) {
        DirListEventArgs args = new DirListEventArgs();
        args.dirlist = (DirectoryInfo[])state;
        handler(this, args);
      }
    }
  }

  public class DirListEventArgs : System.EventArgs {
    public DirectoryInfo[] dirlist;
  }
}

QuestionHow to run application from network folder Pin
AndrusM29-Jul-08 23:12
AndrusM29-Jul-08 23:12 
AnswerRe: How to run application from network folder Pin
Simon P Stevens29-Jul-08 23:47
Simon P Stevens29-Jul-08 23:47 
GeneralRe: How to run application from network folder Pin
AndrusM30-Jul-08 0:25
AndrusM30-Jul-08 0:25 
GeneralRe: How to run application from network folder Pin
Simon P Stevens30-Jul-08 1:16
Simon P Stevens30-Jul-08 1:16 
GeneralRe: How to run application from network folder Pin
AndrusM30-Jul-08 1:22
AndrusM30-Jul-08 1:22 
GeneralRe: How to run application from network folder Pin
Simon P Stevens30-Jul-08 1:34
Simon P Stevens30-Jul-08 1:34 
GeneralRe: How to run application from network folder Pin
AndrusM30-Jul-08 7:25
AndrusM30-Jul-08 7:25 
GeneralRe: How to run application from network folder Pin
Simon P Stevens30-Jul-08 21:30
Simon P Stevens30-Jul-08 21:30 
GeneralRe: How to run application from network folder Pin
AndrusM30-Jul-08 22:38
AndrusM30-Jul-08 22:38 
GeneralRe: How to run application from network folder Pin
AndrusM30-Jul-08 1:35
AndrusM30-Jul-08 1:35 
GeneralRe: How to run application from network folder Pin
Simon P Stevens30-Jul-08 1:41
Simon P Stevens30-Jul-08 1:41 
GeneralRe: How to run application from network folder Pin
AndrusM30-Jul-08 7:27
AndrusM30-Jul-08 7:27 
GeneralRe: How to run application from network folder Pin
mav.northwind30-Jul-08 19:03
mav.northwind30-Jul-08 19:03 
GeneralRe: How to run application from network folder Pin
AndrusM30-Jul-08 23:02
AndrusM30-Jul-08 23:02 
GeneralRe: How to run application from network folder Pin
mav.northwind31-Jul-08 8:36
mav.northwind31-Jul-08 8:36 
GeneralRe: How to run application from network folder Pin
AndrusM31-Jul-08 9:13
AndrusM31-Jul-08 9:13 
GeneralRe: How to run application from network folder Pin
mav.northwind31-Jul-08 18:22
mav.northwind31-Jul-08 18:22 

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.