Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error with ComponentModel.ISynchronizeInvoke as parameter

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
566
US
Colleagues,
Another problem was encountered:
Program: FileWatcher_C ("C" stands for "Console");
Based on FileSystemWatcher class;
When run (Debug mode) in VS 2022 IDE, throws the following error:

2024-04-26_ArgumentIsMissing_p17nsq.jpg


Here's the starting code:

Code:
'====================================================================================================================================
Private Sub StartWatch(fileWatcher_C As ComponentModel.ISynchronizeInvoke)
'====================================================================================================================================
fsWatch = New FileSystemWatcher(gsWorkDir)

fsWatch.SynchronizingObject = fileWatcher_C

In the WinForms app, it was the Start Watch button's Private Sub StartWatch_Click(sender As Object, e As EventArgs) Handles StartWatch.Click

In the Console app, the argument "ComponentModel.ISynchronizeInvoke" was entered by the IntelliSence suggestion.

What am I doing wrong?

AHWBGA!

Regards,

Ilya
 
Firstly, why do you think you need a synchronizing object for FileSystemWatcher?

Secondly, if you DO need it, then you need t pass it as a parameter to StartWatch, but you do not pass any parameter in the ()brief) bit of code you illustrate. Hence the error.
 
StrongM said:
parameter in the ()brief) bit of code you illustrate

Not sure what's "()brief)", would you be so kind to clarify, please?

Regards,

Ilya
 
Your screenshot shows

Code:
StartWatch()

at line 81

And [tt]()brief)[/tt] should have read [tt](brief)[/tt]
 
I ran the search for "brief" - not found.

Regards,

Ilya
 
Ah, no problem!
Here it is:
Code:
'====================================================================================================================================
Private Sub StartWatch() ' (fileWatcher_C As ComponentModel.ISynchronizeInvoke)
'====================================================================================================================================
fsWatch = New FileSystemWatcher(gsWorkDir)
fsWatch.SynchronizingObject = fileWatcher_C
fsWatch.NotifyFilter = NotifyFilters.CreationTime Or
							  NotifyFilters.DirectoryName Or
							  NotifyFilters.FileName Or
							  NotifyFilters.LastAccess Or
							  NotifyFilters.LastWrite Or
							  NotifyFilters.Security

fsWatch.IncludeSubdirectories = True
fsWatch.Filter = "*.XML"

AddHandler fsWatch.Deleted, AddressOf FileDeleted
AddHandler fsWatch.Changed, AddressOf FileChanged
AddHandler fsWatch.Renamed, AddressOf FileRenamed
AddHandler fsWatch.Created, AddressOf FileCreated

fsWatch.EnableRaisingEvents = True

Dim lsRptLine As String = Replicate("=", 134) + vbCrLf + Format(Now, "yyyy-MM-dd HH:mm") + ": Watch started" + vbCrLf
lsRptLine += Replicate("=", 134) + vbCrLf

My.Computer.FileSystem.WriteAllText(gsLogFile, lsRptLine, True)
End Sub
'====================================================================================================================================


Regards,

Ilya
 
No, I saw enough of that to be able to diagnose the StartWatch parameter issue.

But it is good that you posted it, as I can see that you are STILL trying to use a SynchronizingObject (and, I would imagine getting a new, different error as a result), so I repeat my very first question: ... why do you think you need a SynchronizingObject for FileSystemWatcher?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top