Hi All,

I am asking too many questions too often and it looks like I am not doing my research but I really do. It's just that I code and learn during weekends and all questions arise in a short interval.

For a while I was looking for a way to Pass a Function or Sub as a Parameter, if this is what you were trying to find rickford?

Here is my problem. I have many functions (Background Worker tasks) that I like to do in a Try/Catch block for FINAL versions and without Try/Catch block for BETA versions.

VB Code:
  1. Private Sub bwApp_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bwApp.DoWork
  2.  
  3.         Dim t As New cBwJob(cBwJob.JobType.NEW_TASK)
  4.         t = CType(e.Argument, cBwJob)
  5.  
  6.         Select Case t.Job
  7.  
  8.             Case cBwJob.JobType.ADD_NEW_TRACKS
  9.                 sBwAppAddNewFilesToLibrary(t.TaskData)
  10.  
  11.             Case cBwJob.JobType.CAPITALIZE_FIRST_LETTER
  12.                 sBwAppCaptitalizeWord()
  13.  
  14.             Case cBwJob.JobType.FIND_NEW_TRACKS_FROM_HDD
  15.                 sBwAppFindNewTracksFromHDD()
  16.  
  17.             Case cBwJob.JobType.INITIALIZE_ITUNES
  18.                 sBwAppLoadItunes()
  19.  
  20.             Case cBwJob.JobType.LOAD_ALBUMS
  21.                 sBwAppFillTrackCount()
  22.  
  23.             Case cBwJob.JobType.RATINGS_BACKUP
  24.                 sBwAppRatingsBackup()
  25.  
  26.             Case cBwJob.JobType.RATINGS_RESTORE
  27.                 sBwAppRatingsRestore()
  28.  
  29.             Case cBwJob.JobType.RECOVER_TAGS
  30.                 sBwAppRecoverTags()
  31.  
  32.             Case cBwJob.JobType.REPLACE_WORD
  33.                 sBwAppReplaceTextInTags()
  34.  
  35.             Case cBwJob.JobType.VALIDATE_LIBRARY
  36.  
  37.                 If mAppInfo.ApplicationState = AppInfo.SoftwareCycle.FINAL Then
  38.                     sBwAppValidateLibrary()
  39.                 Else
  40.                     Try
  41.                         sBwAppValidateLibrary()
  42.                     Catch ex As Exception
  43.                         mErrOccured = True
  44.                         Dim lErrLog As New System.IO.StreamWriter(mFilePathErrorLog)
  45.                         lErrLog.WriteLine(String.Format("{0}", ex.Message))
  46.                         lErrLog.WriteLine(String.Format("{0}", ex.StackTrace))
  47.                         lErrLog.Close()
  48.                     End Try
  49.                 End If
  50.  
  51.         End Select
  52.  
  53.     End Sub

If you look at the code above, I have done this for ONE BackgroundWorder tasks and I would like to extend this to all the other tasks. I could do it, but ideally I was hoping for something like this to do:


VB Code:
  1. Private Sub sPerformTask(Function myFunction)
  2.  
  3.      If mAppInfo.ApplicationState = AppInfo.SoftwareCycle.FINAL Then
  4.  
  5.      Try
  6.              Call myFunction()
  7.          Catch ex As Exception
  8.              mErrOccured = True
  9.              Dim lErrLog As New System.IO.StreamWriter(mFilePathErrorLog)
  10.              lErrLog.WriteLine(String.Format("{0}", ex.Message))
  11.              lErrLog.WriteLine(String.Format("{0}", ex.StackTrace))
  12.              lErrLog.Close()
  13.          End Try
  14.  
  15.      Else
  16.        
  17.      Call myFunction()
  18.        
  19.      End If
  20.  
  21. End Sub

So I can call this like

VB Code:
  1. sPerformTask(sBwAppReplaceTextInTags())
VB Code:
  1. sPerformTask(sBwAppReplaceTextInTags())
VB Code:
  1. sPerformTask(sBwAppReplaceTextInTags())

Etc...

I hope I am making myself clear.

Any help would be much appreciated.

Thanks,
McoreD