From cfoust at infostatsystems.com Wed Jan 2 11:27:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 2 Jan 2008 09:27:26 -0800 Subject: [dba-VB] inheriting events In-Reply-To: <001c01c84bf8$89521650$657aa8c0@M90> References: <001c01c84bf8$89521650$657aa8c0@M90> Message-ID: I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, December 31, 2007 2:00 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] inheriting events I designed a base class which has events: Public Class clsProxyProgress Public Event evProcessName(ByVal strProcessName As String) Public Event evDirectory(ByVal strDirectory As String) Public Event evCurrentFile(ByVal strCurrentFile As String) Public Event evFilesCompleted(ByVal intFilesCompleted As Integer) Public Event evFileCnt(ByVal intFileCnt As Integer) Public Event evRowsCopied(ByVal intRowsCopied As Long) Public Event evStatus(ByVal strStatus As String) I then inherit that class in a child class. Public Class clsCSVDataExportSpec Inherits clsProxyProgress The child class clsCSVDataExportSpec cannot "see" the events in the parent, i.e. it cannot do: RaiseEvent evStatus(mstrStatus) even though its parent class has that event. If I try to do this in the child class I get a compile error. In order to get around this I created functions in the parent class clsProxyProgress Public Sub mStatus(ByVal strStatus As String, ByVal blnStatusReset As Boolean, ByVal blnStatusTimeStamp As Boolean) If blnStatusReset Then mstrStatus = "" If blnStatusTimeStamp Then mstrStatus = mstrStatus & vbCrLf & Now() End If If Len(mstrStatus) > 0 Then mstrStatus = mstrStatus & vbCrLf & strStatus Else mstrStatus = strStatus End If RaiseEvent evStatus(mstrStatus) End Sub NOTICE that in the last line of the sub I raise the evStatus. I then call this sub from the child clsCSVDataExportSpec so that the parent class clsProxyProgress raises the event for the child class. I do this simply because if I try to raise the event up in the parent class directly I get a compile error. The whole point of this stuff is to allow a form to sink events and display data in text boxes on the form. In a form class I dimension a variable for this child class: Private WithEvents fclsCSVDataExport As clsCSVDataExportSpec further down I "sink" the events for this class: Private Sub fclsCSVDataExport_evStatus(ByVal strStatus As String) Handles fclsCSVDataExport.evStatus txtStatus.Text = strStatus Application.DoEvents() End Sub In the "Handles ..." the evStatus is a choice in the intellisense dropdown, IOW this form's module "sees" the event that the child class fclsCSVDataExport inherits from its parent class clsProxyProgress. However the sub fclsCSVDataExport_evStatus() never receives control when the Raisevent is executed. I SUSPECT that the issue is that the "Handles ..." needs to be "Handles fclsProxyProgress", i.e. it needs to "handle" the parent of fclsCSVDataExport, not fclsCSVDataExport itself. fclsCSVDataExport is the actual class that performs the data export for me. clsProxyProgress only exists to allow several different such import / export classes inherit common events and code, and I do that so that I can (eventually) have a generic form that dimensions a clsProxyProgress rather than having a specific import or export class such as clsCSVDataExport or clsCSVDataImport. If anyone is following what I am doing and can point me to how to make this work it would be appreciated. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Wed Jan 2 12:39:33 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 2 Jan 2008 13:39:33 -0500 Subject: [dba-VB] inheriting events In-Reply-To: References: <001c01c84bf8$89521650$657aa8c0@M90> Message-ID: <002b01c84d6e$d1eb76f0$657aa8c0@M90> Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust From shamil at users.mns.ru Thu Jan 3 05:43:20 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 14:43:20 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <002b01c84d6e$d1eb76f0$657aa8c0@M90> Message-ID: <006201c84dfd$d7096180$6501a8c0@nant> Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Thu Jan 3 08:11:29 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 3 Jan 2008 09:11:29 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <006201c84dfd$d7096180$6501a8c0@nant> References: <002b01c84d6e$d1eb76f0$657aa8c0@M90> <006201c84dfd$d7096180$6501a8c0@nant> Message-ID: <001001c84e12$89c24fd0$657aa8c0@M90> Shamil, Thanks for the example code. I have a few questions. 1) What does the interface do, and what do interfaces in general do? It seems that they just force you to implement all of the pieces of something? As such they are a programming tool to enforce consistency and reduce errors due to inadvertently leaving something out? Is that the purpose, or something else, or something more? 2) Does each form have its own UI thread, or do all forms share a thread? 3) How do you implement context switching? I definitely want to use a worker thread for each import / export task, and I want to be able to have a dedicated status form for each task. 4) I use a Application.DoEvents() at the end of each event handler to give the system time to refresh the form so that it will display properly. No idea whether that is really required or not. Is your Sleep(500) just something similar, or is it just to slow things down so that the numbers count slowly? Hmm.. as I stare at the code in bewilderment it slowly sinks in. You are using an implements instead of inheritance so that a) The events can be raised directly in the class that wants to raise them instead of having to call a method up in the parent class to raise the method. Much cleaner and easier. b) The DirectCast has something to cast the object to which states that events will be happening. You do understand that I am barely able to understand what it all does, and in fact probably still do not understand it all. Your code is a nice example of how to do this stuff, thanks for taking the time to put this together. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 6:43 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil From shamil at users.mns.ru Thu Jan 3 08:23:35 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 17:23:35 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <006201c84dfd$d7096180$6501a8c0@nant> Message-ID: <000601c84e14$39f2e030$6501a8c0@nant> Hello John, Here is another version of code, which is more suitable for the subject of this thread - events can't be inherited in .NET AFAIK therefore you have to simulate such inheritance by using base class's wrapper protected methods: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) RaiseEvent EventOne(eventSource.ToString() + ": " + msg) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) RaiseEvent EventTwo(eventSource.ToString() + ": " + msg, count) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 2:43 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Thu Jan 3 08:51:10 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 3 Jan 2008 09:51:10 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <000601c84e14$39f2e030$6501a8c0@nant> References: <006201c84dfd$d7096180$6501a8c0@nant> <000601c84e14$39f2e030$6501a8c0@nant> Message-ID: <001401c84e18$14af6600$657aa8c0@M90> Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 9:24 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hello John, Here is another version of code, which is more suitable for the subject of this thread - events can't be inherited in .NET AFAIK therefore you have to simulate such inheritance by using base class's wrapper protected methods: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) RaiseEvent EventOne(eventSource.ToString() + ": " + msg) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) RaiseEvent EventTwo(eventSource.ToString() + ": " + msg, count) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 2:43 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From shamil at users.mns.ru Thu Jan 3 09:05:39 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 18:05:39 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <001001c84e12$89c24fd0$657aa8c0@M90> Message-ID: <000801c84e1a$1a8e51b0$6501a8c0@nant> Hi John, 1. Interfaces Interfaces allow having low coupled still compile time bound (i.e. for sure syntactically correct) code... I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... 2) Yes, every winform has its own UI thread AFAIK 3) Context switching - I have to spend some time making sample solution for that for Winforms - I do not program WinForms apps these days, only ASP.NET. I can do that sample code tomorrow probably. If you're in hurry here is a good source about what have to be done: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 4) Application.DoEvents() - I'd never rely on it. The Sleep(...) I use is just for sample purposes to simulate some work, not to let event to be raised /processed. If you will use context switching then you'll always get correctly updated winform and its controls... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:11 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, Thanks for the example code. I have a few questions. 1) What does the interface do, and what do interfaces in general do? It seems that they just force you to implement all of the pieces of something? As such they are a programming tool to enforce consistency and reduce errors due to inadvertently leaving something out? Is that the purpose, or something else, or something more? 2) Does each form have its own UI thread, or do all forms share a thread? 3) How do you implement context switching? I definitely want to use a worker thread for each import / export task, and I want to be able to have a dedicated status form for each task. 4) I use a Application.DoEvents() at the end of each event handler to give the system time to refresh the form so that it will display properly. No idea whether that is really required or not. Is your Sleep(500) just something similar, or is it just to slow things down so that the numbers count slowly? Hmm.. as I stare at the code in bewilderment it slowly sinks in. You are using an implements instead of inheritance so that a) The events can be raised directly in the class that wants to raise them instead of having to call a method up in the parent class to raise the method. Much cleaner and easier. b) The DirectCast has something to cast the object to which states that events will be happening. You do understand that I am barely able to understand what it all does, and in fact probably still do not understand it all. Your code is a nice example of how to do this stuff, thanks for taking the time to put this together. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 6:43 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Jan 3 09:33:14 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 03 Jan 2008 16:33:14 +0100 Subject: [dba-VB] inheriting events Message-ID: Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined-from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... From shamil at users.mns.ru Thu Jan 3 11:47:29 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 20:47:29 +0300 Subject: [dba-VB] inheriting events In-Reply-To: Message-ID: <000001c84e30$b5949730$6501a8c0@nant> Hi Gustav, Please do not frame "these golden words" :) I mean it's of course better to have all these principles in one's active set of best programming practices... If you frame "these golden words" somebody may think I'm a kind of "preaching for ignorance", and I'm not I think.... Thanks. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 03, 2008 6:33 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 4 06:02:34 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 04 Jan 2008 13:02:34 +0100 Subject: [dba-VB] inheriting events Message-ID: Hi Shamil Rest assured, I do keep them in my head - in fact I think I've always worked this way without feeling ignorant. /gustav >>> shamil at users.mns.ru 03-01-2008 18:47 >>> Hi Gustav, Please do not frame "these golden words" :) I mean it's of course better to have all these principles in one's active set of best programming practices... If you frame "these golden words" somebody may think I'm a kind of "preaching for ignorance", and I'm not I think.... Thanks. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 03, 2008 6:33 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... From shamil at users.mns.ru Fri Jan 4 18:49:11 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 5 Jan 2008 03:49:11 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <001401c84e18$14af6600$657aa8c0@M90> Message-ID: <000001c84f34$c9503630$6501a8c0@nant> Hello John, As promised yesterday - here is a solution with multi-threading based on article I mentioned in this thread already: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 1. Create WinForms sample app with Form1 form 2. Create two buttons Button1 and Button2 on this form 3. Create listbox ListBox1 4. Put this code behind for Form1 and set buttons' click event properly: Public Class Form1 : Implements IStatusDisplay Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() TestModule.MainSync(Me) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() TestModule.MainAsync(Me) End Sub Delegate Sub StringParameterDelegate(ByVal value As String) Public Sub UpdateStatus(ByVal value As String) _ Implements IStatusDisplay.UpdateStatus If (Me.InvokeRequired) Then Me.BeginInvoke(New StringParameterDelegate( _ AddressOf UpdateStatus), New Object() {value}) Return End If ListBox1.Items.Add(value) Application.DoEvents() End Sub End Class 5. put this code into Module1 Option Explicit On Public Interface IStatusDisplay Sub UpdateStatus(ByVal value As String) End Interface Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Protected _display As IStatusDisplay Public Sub New(ByVal display As IStatusDisplay) _display = display End Sub Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventOne(message) _display.UpdateStatus(message) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventTwo(message, count) _display.UpdateStatus(message + ", count=" + count.ToString()) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub MainSync(ByVal display As IStatusDisplay) ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test 'MainAsync() End Sub Sub MainAsync(ByVal display As IStatusDisplay) Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module Enjoy multi-threading! :) If you find bugs please post fixes here. Thanks. -- Shamil P.S. Notes: 1. Watch line wraps in the code above 2. I did leave Console.WriteLine(...) in the above code to see how yesterday's console app code was refactored into winforms code - as you can find that weren't many changes... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:51 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Fri Jan 4 18:53:32 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 4 Jan 2008 19:53:32 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <000001c84f34$c9503630$6501a8c0@nant> References: <001401c84e18$14af6600$657aa8c0@M90> <000001c84f34$c9503630$6501a8c0@nant> Message-ID: <005901c84f35$651c65c0$657aa8c0@M90> Thanks Shamil. I'll absorb this and see how I can apply it to my code. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Friday, January 04, 2008 7:49 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hello John, As promised yesterday - here is a solution with multi-threading based on article I mentioned in this thread already: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 1. Create WinForms sample app with Form1 form 2. Create two buttons Button1 and Button2 on this form 3. Create listbox ListBox1 4. Put this code behind for Form1 and set buttons' click event properly: Public Class Form1 : Implements IStatusDisplay Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() TestModule.MainSync(Me) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() TestModule.MainAsync(Me) End Sub Delegate Sub StringParameterDelegate(ByVal value As String) Public Sub UpdateStatus(ByVal value As String) _ Implements IStatusDisplay.UpdateStatus If (Me.InvokeRequired) Then Me.BeginInvoke(New StringParameterDelegate( _ AddressOf UpdateStatus), New Object() {value}) Return End If ListBox1.Items.Add(value) Application.DoEvents() End Sub End Class 5. put this code into Module1 Option Explicit On Public Interface IStatusDisplay Sub UpdateStatus(ByVal value As String) End Interface Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Protected _display As IStatusDisplay Public Sub New(ByVal display As IStatusDisplay) _display = display End Sub Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventOne(message) _display.UpdateStatus(message) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventTwo(message, count) _display.UpdateStatus(message + ", count=" + count.ToString()) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub MainSync(ByVal display As IStatusDisplay) ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test 'MainAsync() End Sub Sub MainAsync(ByVal display As IStatusDisplay) Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module Enjoy multi-threading! :) If you find bugs please post fixes here. Thanks. -- Shamil P.S. Notes: 1. Watch line wraps in the code above 2. I did leave Console.WriteLine(...) in the above code to see how yesterday's console app code was refactored into winforms code - as you can find that weren't many changes... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:51 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Jan 10 11:18:32 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 10 Jan 2008 18:18:32 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From cfoust at infostatsystems.com Thu Jan 10 14:31:29 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 10 Jan 2008 12:31:29 -0800 Subject: [dba-VB] Compiling Class Library In-Reply-To: References: Message-ID: I don't know if you CAN get rid of the message. You can't run a class library or any class directly, so the message is accurate. You're editing a class library referenced in the other solution/project you have open and trying to immediately reflect those changes. I stopped trying that after the first time. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 9:19 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From R.Griffiths at bury.gov.uk Fri Jan 11 03:06:56 2008 From: R.Griffiths at bury.gov.uk (Griffiths, Richard) Date: Fri, 11 Jan 2008 09:06:56 -0000 Subject: [dba-VB] Compiling Class Library In-Reply-To: References: Message-ID: <200801110850.m0B8oDO11368@smarthost.yourcomms.net> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com ----------------------------------------------------------------- Why not visit our website www.bury.gov.uk ----------------------------------------------------------------- The information contained in this e-mail and any files transmitted with it is for the intended recipient(s) alone. It may contain confidential information that is exempt from the disclosure under English law and may also be covered by legal,professional or other privilege. If you are not the intended recipient, you must not copy, distribute or take any action in reliance on it. If you have received this e-mail in error, please notify us immediately by using the reply facility on your e-mail system. If this message is being transmitted over the Internet, be aware that it may be intercepted by third parties. As a public body, the Council may be required to disclose this e-mail or any response to it under the Freedom of Information Act 2000 unless the information in it is covered by one of the exemptions in the Act. By responding to this e-mail you accept that your response may be subject of recording/monitoring to ensure compliance with the Council's ICT Security Policy. Electronic service accepted only at legalservices at bury.gov.uk and on fax number 0161 253 5119 . ************************************************************* From Gustav at cactus.dk Fri Jan 11 08:29:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 15:29:41 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Charlotte True, but I had to do some debugging which required minor changes to the library which, by the way, is not used by any other project. /gustav >>> cfoust at infostatsystems.com 10-01-2008 21:31:29 >>> I don't know if you CAN get rid of the message. You can't run a class library or any class directly, so the message is accurate. You're editing a class library referenced in the other solution/project you have open and trying to immediately reflect those changes. I stopped trying that after the first time. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 9:19 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From Gustav at cactus.dk Fri Jan 11 08:55:47 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 15:55:47 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Richard OK, that makes sense. But how? If I open Add Reference I have tabs: .NET, COM, Projects, Browse, Recent However, tab Projects is empty. Now, I can add the Class Library as a project, and that causes the main project to be wrapped in a Solution given the name of the main project. Then, if I open Add Reference for either project (main or library), the other project is listed as a reference. Is this what I should do? /gustav >>> R.Griffiths at bury.gov.uk 11-01-2008 10:06:56 >>> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From shamil at users.mns.ru Fri Jan 11 09:35:49 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Fri, 11 Jan 2008 18:35:49 +0300 Subject: [dba-VB] Compiling Class Library In-Reply-To: Message-ID: <000001c85467$a48910f0$6401a8c0@nant> Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 11 10:13:10 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 17:13:10 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Richard Small correction: Then, if I open Add Reference for either project (main or library), the other project is listed as a possible reference. /gustav >>> Gustav at cactus.dk 11-01-2008 15:55:47 >>> Hi Richard OK, that makes sense. But how? If I open Add Reference I have tabs: .NET, COM, Projects, Browse, Recent However, tab Projects is empty. Now, I can add the Class Library as a project, and that causes the main project to be wrapped in a Solution given the name of the main project. Then, if I open Add Reference for either project (main or library), the other project is listed as a reference. Is this what I should do? /gustav >>> R.Griffiths at bury.gov.uk 11-01-2008 10:06:56 >>> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From cfoust at infostatsystems.com Fri Jan 11 10:13:25 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 11 Jan 2008 08:13:25 -0800 Subject: [dba-VB] Compiling Class Library In-Reply-To: <000001c85467$a48910f0$6401a8c0@nant> References: <000001c85467$a48910f0$6401a8c0@nant> Message-ID: Yes, that's the way we build ours too. Our apps are solutions that contain multiple projects, some of which are shared with our other apps. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Friday, January 11, 2008 7:36 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Compiling Class Library Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 11 10:29:03 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 17:29:03 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Shamil and Charlotte The scenario you and Charlotte describe seems to be the right way to do it when the classlibs are under your control. What I did originally was to reference the compiled dll, and I guess there really is no reason to do so unless you don't have the source available. Then, when referencing the dll of the classlib, (re)building the classlib doesn't seem to push the changes to the main project. I agree with Shamil that VS is great. The more you work with it the more you appreciate it and all its features and how well they are thought out ... /gustav >>> shamil at users.mns.ru 11-01-2008 16:35:49 >>> Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From john at winhaven.net Wed Jan 23 13:58:52 2008 From: john at winhaven.net (John Bartow) Date: Wed, 23 Jan 2008 13:58:52 -0600 Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell Message-ID: <200801231958.m0NJwkZF002102@databaseadvisors.com> It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Bryan Carbonell with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com From john at winhaven.net Wed Jan 23 14:00:27 2008 From: john at winhaven.net (John Bartow) Date: Wed, 23 Jan 2008 14:00:27 -0600 Subject: [dba-VB] DBA Award Announcement - Jim Lawrence Message-ID: <200801232000.m0NK0Oin003206@databaseadvisors.com> It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Jim Lawrence with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. http://www.winhaven.net/misc/JimLawrence.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com From garykjos at gmail.com Wed Jan 23 14:59:50 2008 From: garykjos at gmail.com (Gary Kjos) Date: Wed, 23 Jan 2008 14:59:50 -0600 Subject: [dba-VB] [dba-OT] DBA Award Announcement - Bryan Carbonnell In-Reply-To: <200801231958.m0NJwkZF002102@databaseadvisors.com> References: <200801231958.m0NJwkZF002102@databaseadvisors.com> Message-ID: Yes, THANK YOU BRYAN! GK On 1/23/08, John Bartow wrote: > It is with great pleasure that the Board of Directors for Database Advisors, > Inc. presents Bryan Carbonell with a Special Service Award in deep > appreciation for all that he has done for Database Advisors as List Master. > We value his dedication, professionalism and the sharing of his talents and > we look forward to continuing our work together. > > Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm > > John Bartow, President > Database Advisors, Inc. > Email: mailto:president at databaseadvisors.com > Website: http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-OT mailing list > dba-OT at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-ot > Website: http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com From garykjos at gmail.com Wed Jan 23 15:00:34 2008 From: garykjos at gmail.com (Gary Kjos) Date: Wed, 23 Jan 2008 15:00:34 -0600 Subject: [dba-VB] [dba-OT] DBA Award Announcement - Jim Lawrence In-Reply-To: <200801232000.m0NK0Oin003206@databaseadvisors.com> References: <200801232000.m0NK0Oin003206@databaseadvisors.com> Message-ID: Yes, THANK YOU JIM! GK On 1/23/08, John Bartow wrote: > It is with great pleasure that the Board of Directors for Database Advisors, > Inc. presents Jim Lawrence with a Special Service Award in deep appreciation > for all that he has done for Database Advisors as List Master. We value his > dedication, professionalism and the sharing of his talents and we look > forward to continuing our work together. > > http://www.winhaven.net/misc/JimLawrence.htm > > John Bartow, President > Database Advisors, Inc. > Email: mailto:president at databaseadvisors.com > Website: http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-OT mailing list > dba-OT at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-ot > Website: http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com From cfoust at infostatsystems.com Wed Jan 23 15:16:58 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 23 Jan 2008 13:16:58 -0800 Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell In-Reply-To: <200801231958.m0NJwkZF002102@databaseadvisors.com> References: <200801231958.m0NJwkZF002102@databaseadvisors.com> Message-ID: Congratulations, Bryan. No wonder I didn't see this in AccessD!! LOL Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Bartow Sent: Wednesday, January 23, 2008 11:59 AM To: dba-sqlserver at databaseadvisors.com; _DBA-Access; dba-ot at databaseadvisors.com; _DBA-Owners; _DBA-Tech; dba-vb at databaseadvisors.com Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Bryan Carbonell with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 25 05:02:16 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 12:02:16 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of-dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Fri Jan 25 10:23:10 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Fri, 25 Jan 2008 19:23:10 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <001801c85f6e$93a90cb0$6501a8c0@nant> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 25 13:16:09 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:16:09 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil True, and the benchmarks in article shows this too. But for this case with only about 5000 records speed is not important and then I learn something new. It took me a while to find out that you have to use this syntax to create the procedure: CREATE PROCEDURE Something AS EXTERNAL NAME assembly.[namespace.class].method This is for SQL Server 2005 and .Net 2.0. Don't know if it has improved in SQL Server 2008. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From Gustav at cactus.dk Fri Jan 25 13:37:45 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:37:45 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From Gustav at cactus.dk Fri Jan 25 13:54:24 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:54:24 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Located this on the issue: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=95554 /gustav >>> Gustav at cactus.dk 25-01-2008 20:37:45 >>> Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Fri Jan 25 15:09:30 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 26 Jan 2008 00:09:30 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <000601c85f96$93d28680$6501a8c0@nant> Hello Gustav, CLR stored procedures can have output parameters (but not return values) of many different types... There are also CLR Scalar-Valued Functions (SVFs), which return a single value. SVFs can return any scalar type, excluding varchar, char, rowversion, text, ntext, image, timestamp, table, or cursor. This information is from the book: "Professional SQL ServerT 2005 CLR Programming with Stored Procedures, Functions, Triggers, Aggregates, and Types" By Derek Comingore and Douglas Hinson which is very good and covers all(?) the aspects on developing and deploying managed SPs, SVFs, triggers, ... for MS SQL 2005... I haven't yet used SQL 2005 CLR programming - I'm waiting for a customer to request for such programming :) - as far as I see from the book I mentioned above there is no any "black magic" there... BTW, this book has very detailed chapter (Chapter 5) comparing CLR and T-SQL performance - I'd dare to give here an short summary of this chapter: << As it relates to a performance comparison between SQL CLR and T-SQL, we have shown in this chapter that: - String parsing and processing perform better with less CPU resources using CLR base classes. - Computation of even simple proportions performs better in SQL CLR. - SQL CLR table-valued functions can stream results faster to client than T-SQL - T-SQL is still the king of data manipulation, extraction, and updating. >> I haven't seen yet/tried MS SQL 2008 - I will probably do that end of this year if not later... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 10:38 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Sun Jan 27 16:19:23 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 27 Jan 2008 23:19:23 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil Thanks. Looks like a very good reference. /gustav >>> shamil at users.mns.ru 25-01-2008 22:09 >>> Hello Gustav, CLR stored procedures can have output parameters (but not return values) of many different types... There are also CLR Scalar-Valued Functions (SVFs), which return a single value. SVFs can return any scalar type, excluding varchar, char, rowversion, text, ntext, image, timestamp, table, or cursor. This information is from the book: "Professional SQL ServerT 2005 CLR Programming with Stored Procedures, Functions, Triggers, Aggregates, and Types" By Derek Comingore and Douglas Hinson which is very good and covers all(?) the aspects on developing and deploying managed SPs, SVFs, triggers, ... for MS SQL 2005... I haven't yet used SQL 2005 CLR programming - I'm waiting for a customer to request for such programming :) - as far as I see from the book I mentioned above there is no any "black magic" there... BTW, this book has very detailed chapter (Chapter 5) comparing CLR and T-SQL performance - I'd dare to give here an short summary of this chapter: << As it relates to a performance comparison between SQL CLR and T-SQL, we have shown in this chapter that: - String parsing and processing perform better with less CPU resources using CLR base classes. - Computation of even simple proportions performs better in SQL CLR. - SQL CLR table-valued functions can stream results faster to client than T-SQL - T-SQL is still the king of data manipulation, extraction, and updating. >> I haven't seen yet/tried MS SQL 2008 - I will probably do that end of this year if not later... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 10:38 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From djkr at msn.com Sun Jan 27 18:36:37 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:36:37 -0000 Subject: [dba-VB] Performance in disc partitions In-Reply-To: Message-ID: I am about to partition a new disc. One partition will be very active in terms of reads and writes, another almost dormant. Is there any advantage in performance terms in having the active partition as the 'first' one on the disc? Or the last one? It's a long time since I was involved in disc layout at a low level, and I'm wondering whether 'cylinders' these days are still all the same size, with the data near the edge of the platter just more spread out than that near the spindle - or not? TIA John From djkr at msn.com Sun Jan 27 18:46:46 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:46:46 -0000 Subject: [dba-VB] Performance in disc partitions In-Reply-To: Message-ID: Aargh - sorry! I misposted this. It should have been to dba-Tech, where it now is. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of DJK(John) Robinson Sent: 28 January 2008 00:37 To: 'Discussion concerning Visual Basic and related programming issues.' Subject: [dba-VB] Performance in disc partitions I am about to partition a new disc. One partition will be very active in terms of reads and writes, another almost dormant. Is there any advantage in performance terms in having the active partition as the 'first' one on the disc? Or the last one? It's a long time since I was involved in disc layout at a low level, and I'm wondering whether 'cylinders' these days are still all the same size, with the data near the edge of the platter just more spread out than that near the spindle - or not? TIA John _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From djkr at msn.com Sun Jan 27 18:49:29 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:49:29 -0000 Subject: [dba-VB] Recall: Performance in disc partitions Message-ID: The sender would like to recall the message, "Performance in disc partitions". From Gustav at cactus.dk Thu Jan 31 05:25:08 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 31 Jan 2008 12:25:08 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil et al Here is what I did. Some of the data (from some "foreign" apps) are stored in mdb files. These I link to the SQL Server as "linked servers" to be able to import the data to the SQL Server on a regular basis. This is done via some simple queries (no joins, no aggregating) with some basic manipulation writing to similar tables in the server. These queries I can control from Visual Studio. However, VS will not connect directly to a linked server, only to normal databases of the SQL Server. So you will have to connect to such a database and then reference the linked server in a query. One advantage is, that the SQL syntax of such a query is that of SQL Server, not Access/JET. It took some research to locate the syntax for referencing a linked mdb - note the last line in the example here: Select varenr as ItemId, dessnr as DessinNo, case when ( case when isnumeric(right(dessnr, charindex('-', reverse(dessnr)))) <> 0 then convert(bigint, right(dessnr, charindex('-', reverse(dessnr)) - 1)) else 0 end) between 1 and 99 and charindex('-', dessnr) > 0 then rtrim(left( dessnr, len(dessnr) - charindex('-', reverse(dessnr)))) else dessnr end as DessinId >From linkeddb...tblDessin The advantage is, that all that is needed to be set up at the server is the links to the mdb files - the queries are controlled and maintained from VS, and the client apps do not need to know anything about the physical location of the mdb files, neither do they need to establish connections to these. >From this point I can easily store the data in server tables while recording some log details of success or failure. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Thu Jan 31 07:27:19 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 31 Jan 2008 16:27:19 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <002101c8640d$01ae6d20$6501a8c0@nant> Hi Gustav, Yes, I did read about "linked servers", which could be any OLE DB (and ODBC?) data source AFAIK but I have never used them. Please post here some notes later when you get good experience of using them in your test/deployment environments... Thank you. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 31, 2008 2:25 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil et al Here is what I did. Some of the data (from some "foreign" apps) are stored in mdb files. These I link to the SQL Server as "linked servers" to be able to import the data to the SQL Server on a regular basis. This is done via some simple queries (no joins, no aggregating) with some basic manipulation writing to similar tables in the server. These queries I can control from Visual Studio. However, VS will not connect directly to a linked server, only to normal databases of the SQL Server. So you will have to connect to such a database and then reference the linked server in a query. One advantage is, that the SQL syntax of such a query is that of SQL Server, not Access/JET. It took some research to locate the syntax for referencing a linked mdb - note the last line in the example here: Select varenr as ItemId, dessnr as DessinNo, case when ( case when isnumeric(right(dessnr, charindex('-', reverse(dessnr)))) <> 0 then convert(bigint, right(dessnr, charindex('-', reverse(dessnr)) - 1)) else 0 end) between 1 and 99 and charindex('-', dessnr) > 0 then rtrim(left( dessnr, len(dessnr) - charindex('-', reverse(dessnr)))) else dessnr end as DessinId >From linkeddb...tblDessin The advantage is, that all that is needed to be set up at the server is the links to the mdb files - the queries are controlled and maintained from VS, and the client apps do not need to know anything about the physical location of the mdb files, neither do they need to establish connections to these. >From this point I can easily store the data in server tables while recording some log details of success or failure. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From cfoust at infostatsystems.com Wed Jan 2 11:27:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 2 Jan 2008 09:27:26 -0800 Subject: [dba-VB] inheriting events In-Reply-To: <001c01c84bf8$89521650$657aa8c0@M90> References: <001c01c84bf8$89521650$657aa8c0@M90> Message-ID: I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, December 31, 2007 2:00 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] inheriting events I designed a base class which has events: Public Class clsProxyProgress Public Event evProcessName(ByVal strProcessName As String) Public Event evDirectory(ByVal strDirectory As String) Public Event evCurrentFile(ByVal strCurrentFile As String) Public Event evFilesCompleted(ByVal intFilesCompleted As Integer) Public Event evFileCnt(ByVal intFileCnt As Integer) Public Event evRowsCopied(ByVal intRowsCopied As Long) Public Event evStatus(ByVal strStatus As String) I then inherit that class in a child class. Public Class clsCSVDataExportSpec Inherits clsProxyProgress The child class clsCSVDataExportSpec cannot "see" the events in the parent, i.e. it cannot do: RaiseEvent evStatus(mstrStatus) even though its parent class has that event. If I try to do this in the child class I get a compile error. In order to get around this I created functions in the parent class clsProxyProgress Public Sub mStatus(ByVal strStatus As String, ByVal blnStatusReset As Boolean, ByVal blnStatusTimeStamp As Boolean) If blnStatusReset Then mstrStatus = "" If blnStatusTimeStamp Then mstrStatus = mstrStatus & vbCrLf & Now() End If If Len(mstrStatus) > 0 Then mstrStatus = mstrStatus & vbCrLf & strStatus Else mstrStatus = strStatus End If RaiseEvent evStatus(mstrStatus) End Sub NOTICE that in the last line of the sub I raise the evStatus. I then call this sub from the child clsCSVDataExportSpec so that the parent class clsProxyProgress raises the event for the child class. I do this simply because if I try to raise the event up in the parent class directly I get a compile error. The whole point of this stuff is to allow a form to sink events and display data in text boxes on the form. In a form class I dimension a variable for this child class: Private WithEvents fclsCSVDataExport As clsCSVDataExportSpec further down I "sink" the events for this class: Private Sub fclsCSVDataExport_evStatus(ByVal strStatus As String) Handles fclsCSVDataExport.evStatus txtStatus.Text = strStatus Application.DoEvents() End Sub In the "Handles ..." the evStatus is a choice in the intellisense dropdown, IOW this form's module "sees" the event that the child class fclsCSVDataExport inherits from its parent class clsProxyProgress. However the sub fclsCSVDataExport_evStatus() never receives control when the Raisevent is executed. I SUSPECT that the issue is that the "Handles ..." needs to be "Handles fclsProxyProgress", i.e. it needs to "handle" the parent of fclsCSVDataExport, not fclsCSVDataExport itself. fclsCSVDataExport is the actual class that performs the data export for me. clsProxyProgress only exists to allow several different such import / export classes inherit common events and code, and I do that so that I can (eventually) have a generic form that dimensions a clsProxyProgress rather than having a specific import or export class such as clsCSVDataExport or clsCSVDataImport. If anyone is following what I am doing and can point me to how to make this work it would be appreciated. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Wed Jan 2 12:39:33 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 2 Jan 2008 13:39:33 -0500 Subject: [dba-VB] inheriting events In-Reply-To: References: <001c01c84bf8$89521650$657aa8c0@M90> Message-ID: <002b01c84d6e$d1eb76f0$657aa8c0@M90> Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust From shamil at users.mns.ru Thu Jan 3 05:43:20 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 14:43:20 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <002b01c84d6e$d1eb76f0$657aa8c0@M90> Message-ID: <006201c84dfd$d7096180$6501a8c0@nant> Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Thu Jan 3 08:11:29 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 3 Jan 2008 09:11:29 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <006201c84dfd$d7096180$6501a8c0@nant> References: <002b01c84d6e$d1eb76f0$657aa8c0@M90> <006201c84dfd$d7096180$6501a8c0@nant> Message-ID: <001001c84e12$89c24fd0$657aa8c0@M90> Shamil, Thanks for the example code. I have a few questions. 1) What does the interface do, and what do interfaces in general do? It seems that they just force you to implement all of the pieces of something? As such they are a programming tool to enforce consistency and reduce errors due to inadvertently leaving something out? Is that the purpose, or something else, or something more? 2) Does each form have its own UI thread, or do all forms share a thread? 3) How do you implement context switching? I definitely want to use a worker thread for each import / export task, and I want to be able to have a dedicated status form for each task. 4) I use a Application.DoEvents() at the end of each event handler to give the system time to refresh the form so that it will display properly. No idea whether that is really required or not. Is your Sleep(500) just something similar, or is it just to slow things down so that the numbers count slowly? Hmm.. as I stare at the code in bewilderment it slowly sinks in. You are using an implements instead of inheritance so that a) The events can be raised directly in the class that wants to raise them instead of having to call a method up in the parent class to raise the method. Much cleaner and easier. b) The DirectCast has something to cast the object to which states that events will be happening. You do understand that I am barely able to understand what it all does, and in fact probably still do not understand it all. Your code is a nice example of how to do this stuff, thanks for taking the time to put this together. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 6:43 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil From shamil at users.mns.ru Thu Jan 3 08:23:35 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 17:23:35 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <006201c84dfd$d7096180$6501a8c0@nant> Message-ID: <000601c84e14$39f2e030$6501a8c0@nant> Hello John, Here is another version of code, which is more suitable for the subject of this thread - events can't be inherited in .NET AFAIK therefore you have to simulate such inheritance by using base class's wrapper protected methods: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) RaiseEvent EventOne(eventSource.ToString() + ": " + msg) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) RaiseEvent EventTwo(eventSource.ToString() + ": " + msg, count) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 2:43 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Thu Jan 3 08:51:10 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 3 Jan 2008 09:51:10 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <000601c84e14$39f2e030$6501a8c0@nant> References: <006201c84dfd$d7096180$6501a8c0@nant> <000601c84e14$39f2e030$6501a8c0@nant> Message-ID: <001401c84e18$14af6600$657aa8c0@M90> Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 9:24 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hello John, Here is another version of code, which is more suitable for the subject of this thread - events can't be inherited in .NET AFAIK therefore you have to simulate such inheritance by using base class's wrapper protected methods: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) RaiseEvent EventOne(eventSource.ToString() + ": " + msg) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) RaiseEvent EventTwo(eventSource.ToString() + ": " + msg, count) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 2:43 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From shamil at users.mns.ru Thu Jan 3 09:05:39 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 18:05:39 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <001001c84e12$89c24fd0$657aa8c0@M90> Message-ID: <000801c84e1a$1a8e51b0$6501a8c0@nant> Hi John, 1. Interfaces Interfaces allow having low coupled still compile time bound (i.e. for sure syntactically correct) code... I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... 2) Yes, every winform has its own UI thread AFAIK 3) Context switching - I have to spend some time making sample solution for that for Winforms - I do not program WinForms apps these days, only ASP.NET. I can do that sample code tomorrow probably. If you're in hurry here is a good source about what have to be done: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 4) Application.DoEvents() - I'd never rely on it. The Sleep(...) I use is just for sample purposes to simulate some work, not to let event to be raised /processed. If you will use context switching then you'll always get correctly updated winform and its controls... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:11 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, Thanks for the example code. I have a few questions. 1) What does the interface do, and what do interfaces in general do? It seems that they just force you to implement all of the pieces of something? As such they are a programming tool to enforce consistency and reduce errors due to inadvertently leaving something out? Is that the purpose, or something else, or something more? 2) Does each form have its own UI thread, or do all forms share a thread? 3) How do you implement context switching? I definitely want to use a worker thread for each import / export task, and I want to be able to have a dedicated status form for each task. 4) I use a Application.DoEvents() at the end of each event handler to give the system time to refresh the form so that it will display properly. No idea whether that is really required or not. Is your Sleep(500) just something similar, or is it just to slow things down so that the numbers count slowly? Hmm.. as I stare at the code in bewilderment it slowly sinks in. You are using an implements instead of inheritance so that a) The events can be raised directly in the class that wants to raise them instead of having to call a method up in the parent class to raise the method. Much cleaner and easier. b) The DirectCast has something to cast the object to which states that events will be happening. You do understand that I am barely able to understand what it all does, and in fact probably still do not understand it all. Your code is a nice example of how to do this stuff, thanks for taking the time to put this together. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 6:43 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Jan 3 09:33:14 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 03 Jan 2008 16:33:14 +0100 Subject: [dba-VB] inheriting events Message-ID: Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined-from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... From shamil at users.mns.ru Thu Jan 3 11:47:29 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 20:47:29 +0300 Subject: [dba-VB] inheriting events In-Reply-To: Message-ID: <000001c84e30$b5949730$6501a8c0@nant> Hi Gustav, Please do not frame "these golden words" :) I mean it's of course better to have all these principles in one's active set of best programming practices... If you frame "these golden words" somebody may think I'm a kind of "preaching for ignorance", and I'm not I think.... Thanks. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 03, 2008 6:33 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 4 06:02:34 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 04 Jan 2008 13:02:34 +0100 Subject: [dba-VB] inheriting events Message-ID: Hi Shamil Rest assured, I do keep them in my head - in fact I think I've always worked this way without feeling ignorant. /gustav >>> shamil at users.mns.ru 03-01-2008 18:47 >>> Hi Gustav, Please do not frame "these golden words" :) I mean it's of course better to have all these principles in one's active set of best programming practices... If you frame "these golden words" somebody may think I'm a kind of "preaching for ignorance", and I'm not I think.... Thanks. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 03, 2008 6:33 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... From shamil at users.mns.ru Fri Jan 4 18:49:11 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 5 Jan 2008 03:49:11 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <001401c84e18$14af6600$657aa8c0@M90> Message-ID: <000001c84f34$c9503630$6501a8c0@nant> Hello John, As promised yesterday - here is a solution with multi-threading based on article I mentioned in this thread already: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 1. Create WinForms sample app with Form1 form 2. Create two buttons Button1 and Button2 on this form 3. Create listbox ListBox1 4. Put this code behind for Form1 and set buttons' click event properly: Public Class Form1 : Implements IStatusDisplay Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() TestModule.MainSync(Me) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() TestModule.MainAsync(Me) End Sub Delegate Sub StringParameterDelegate(ByVal value As String) Public Sub UpdateStatus(ByVal value As String) _ Implements IStatusDisplay.UpdateStatus If (Me.InvokeRequired) Then Me.BeginInvoke(New StringParameterDelegate( _ AddressOf UpdateStatus), New Object() {value}) Return End If ListBox1.Items.Add(value) Application.DoEvents() End Sub End Class 5. put this code into Module1 Option Explicit On Public Interface IStatusDisplay Sub UpdateStatus(ByVal value As String) End Interface Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Protected _display As IStatusDisplay Public Sub New(ByVal display As IStatusDisplay) _display = display End Sub Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventOne(message) _display.UpdateStatus(message) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventTwo(message, count) _display.UpdateStatus(message + ", count=" + count.ToString()) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub MainSync(ByVal display As IStatusDisplay) ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test 'MainAsync() End Sub Sub MainAsync(ByVal display As IStatusDisplay) Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module Enjoy multi-threading! :) If you find bugs please post fixes here. Thanks. -- Shamil P.S. Notes: 1. Watch line wraps in the code above 2. I did leave Console.WriteLine(...) in the above code to see how yesterday's console app code was refactored into winforms code - as you can find that weren't many changes... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:51 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Fri Jan 4 18:53:32 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 4 Jan 2008 19:53:32 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <000001c84f34$c9503630$6501a8c0@nant> References: <001401c84e18$14af6600$657aa8c0@M90> <000001c84f34$c9503630$6501a8c0@nant> Message-ID: <005901c84f35$651c65c0$657aa8c0@M90> Thanks Shamil. I'll absorb this and see how I can apply it to my code. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Friday, January 04, 2008 7:49 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hello John, As promised yesterday - here is a solution with multi-threading based on article I mentioned in this thread already: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 1. Create WinForms sample app with Form1 form 2. Create two buttons Button1 and Button2 on this form 3. Create listbox ListBox1 4. Put this code behind for Form1 and set buttons' click event properly: Public Class Form1 : Implements IStatusDisplay Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() TestModule.MainSync(Me) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() TestModule.MainAsync(Me) End Sub Delegate Sub StringParameterDelegate(ByVal value As String) Public Sub UpdateStatus(ByVal value As String) _ Implements IStatusDisplay.UpdateStatus If (Me.InvokeRequired) Then Me.BeginInvoke(New StringParameterDelegate( _ AddressOf UpdateStatus), New Object() {value}) Return End If ListBox1.Items.Add(value) Application.DoEvents() End Sub End Class 5. put this code into Module1 Option Explicit On Public Interface IStatusDisplay Sub UpdateStatus(ByVal value As String) End Interface Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Protected _display As IStatusDisplay Public Sub New(ByVal display As IStatusDisplay) _display = display End Sub Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventOne(message) _display.UpdateStatus(message) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventTwo(message, count) _display.UpdateStatus(message + ", count=" + count.ToString()) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub MainSync(ByVal display As IStatusDisplay) ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test 'MainAsync() End Sub Sub MainAsync(ByVal display As IStatusDisplay) Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module Enjoy multi-threading! :) If you find bugs please post fixes here. Thanks. -- Shamil P.S. Notes: 1. Watch line wraps in the code above 2. I did leave Console.WriteLine(...) in the above code to see how yesterday's console app code was refactored into winforms code - as you can find that weren't many changes... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:51 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Jan 10 11:18:32 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 10 Jan 2008 18:18:32 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From cfoust at infostatsystems.com Thu Jan 10 14:31:29 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 10 Jan 2008 12:31:29 -0800 Subject: [dba-VB] Compiling Class Library In-Reply-To: References: Message-ID: I don't know if you CAN get rid of the message. You can't run a class library or any class directly, so the message is accurate. You're editing a class library referenced in the other solution/project you have open and trying to immediately reflect those changes. I stopped trying that after the first time. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 9:19 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From R.Griffiths at bury.gov.uk Fri Jan 11 03:06:56 2008 From: R.Griffiths at bury.gov.uk (Griffiths, Richard) Date: Fri, 11 Jan 2008 09:06:56 -0000 Subject: [dba-VB] Compiling Class Library In-Reply-To: References: Message-ID: <200801110850.m0B8oDO11368@smarthost.yourcomms.net> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com ----------------------------------------------------------------- Why not visit our website www.bury.gov.uk ----------------------------------------------------------------- The information contained in this e-mail and any files transmitted with it is for the intended recipient(s) alone. It may contain confidential information that is exempt from the disclosure under English law and may also be covered by legal,professional or other privilege. If you are not the intended recipient, you must not copy, distribute or take any action in reliance on it. If you have received this e-mail in error, please notify us immediately by using the reply facility on your e-mail system. If this message is being transmitted over the Internet, be aware that it may be intercepted by third parties. As a public body, the Council may be required to disclose this e-mail or any response to it under the Freedom of Information Act 2000 unless the information in it is covered by one of the exemptions in the Act. By responding to this e-mail you accept that your response may be subject of recording/monitoring to ensure compliance with the Council's ICT Security Policy. Electronic service accepted only at legalservices at bury.gov.uk and on fax number 0161 253 5119 . ************************************************************* From Gustav at cactus.dk Fri Jan 11 08:29:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 15:29:41 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Charlotte True, but I had to do some debugging which required minor changes to the library which, by the way, is not used by any other project. /gustav >>> cfoust at infostatsystems.com 10-01-2008 21:31:29 >>> I don't know if you CAN get rid of the message. You can't run a class library or any class directly, so the message is accurate. You're editing a class library referenced in the other solution/project you have open and trying to immediately reflect those changes. I stopped trying that after the first time. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 9:19 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From Gustav at cactus.dk Fri Jan 11 08:55:47 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 15:55:47 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Richard OK, that makes sense. But how? If I open Add Reference I have tabs: .NET, COM, Projects, Browse, Recent However, tab Projects is empty. Now, I can add the Class Library as a project, and that causes the main project to be wrapped in a Solution given the name of the main project. Then, if I open Add Reference for either project (main or library), the other project is listed as a reference. Is this what I should do? /gustav >>> R.Griffiths at bury.gov.uk 11-01-2008 10:06:56 >>> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From shamil at users.mns.ru Fri Jan 11 09:35:49 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Fri, 11 Jan 2008 18:35:49 +0300 Subject: [dba-VB] Compiling Class Library In-Reply-To: Message-ID: <000001c85467$a48910f0$6401a8c0@nant> Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 11 10:13:10 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 17:13:10 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Richard Small correction: Then, if I open Add Reference for either project (main or library), the other project is listed as a possible reference. /gustav >>> Gustav at cactus.dk 11-01-2008 15:55:47 >>> Hi Richard OK, that makes sense. But how? If I open Add Reference I have tabs: .NET, COM, Projects, Browse, Recent However, tab Projects is empty. Now, I can add the Class Library as a project, and that causes the main project to be wrapped in a Solution given the name of the main project. Then, if I open Add Reference for either project (main or library), the other project is listed as a reference. Is this what I should do? /gustav >>> R.Griffiths at bury.gov.uk 11-01-2008 10:06:56 >>> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From cfoust at infostatsystems.com Fri Jan 11 10:13:25 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 11 Jan 2008 08:13:25 -0800 Subject: [dba-VB] Compiling Class Library In-Reply-To: <000001c85467$a48910f0$6401a8c0@nant> References: <000001c85467$a48910f0$6401a8c0@nant> Message-ID: Yes, that's the way we build ours too. Our apps are solutions that contain multiple projects, some of which are shared with our other apps. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Friday, January 11, 2008 7:36 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Compiling Class Library Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 11 10:29:03 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 17:29:03 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Shamil and Charlotte The scenario you and Charlotte describe seems to be the right way to do it when the classlibs are under your control. What I did originally was to reference the compiled dll, and I guess there really is no reason to do so unless you don't have the source available. Then, when referencing the dll of the classlib, (re)building the classlib doesn't seem to push the changes to the main project. I agree with Shamil that VS is great. The more you work with it the more you appreciate it and all its features and how well they are thought out ... /gustav >>> shamil at users.mns.ru 11-01-2008 16:35:49 >>> Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From john at winhaven.net Wed Jan 23 13:58:52 2008 From: john at winhaven.net (John Bartow) Date: Wed, 23 Jan 2008 13:58:52 -0600 Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell Message-ID: <200801231958.m0NJwkZF002102@databaseadvisors.com> It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Bryan Carbonell with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com From john at winhaven.net Wed Jan 23 14:00:27 2008 From: john at winhaven.net (John Bartow) Date: Wed, 23 Jan 2008 14:00:27 -0600 Subject: [dba-VB] DBA Award Announcement - Jim Lawrence Message-ID: <200801232000.m0NK0Oin003206@databaseadvisors.com> It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Jim Lawrence with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. http://www.winhaven.net/misc/JimLawrence.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com From garykjos at gmail.com Wed Jan 23 14:59:50 2008 From: garykjos at gmail.com (Gary Kjos) Date: Wed, 23 Jan 2008 14:59:50 -0600 Subject: [dba-VB] [dba-OT] DBA Award Announcement - Bryan Carbonnell In-Reply-To: <200801231958.m0NJwkZF002102@databaseadvisors.com> References: <200801231958.m0NJwkZF002102@databaseadvisors.com> Message-ID: Yes, THANK YOU BRYAN! GK On 1/23/08, John Bartow wrote: > It is with great pleasure that the Board of Directors for Database Advisors, > Inc. presents Bryan Carbonell with a Special Service Award in deep > appreciation for all that he has done for Database Advisors as List Master. > We value his dedication, professionalism and the sharing of his talents and > we look forward to continuing our work together. > > Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm > > John Bartow, President > Database Advisors, Inc. > Email: mailto:president at databaseadvisors.com > Website: http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-OT mailing list > dba-OT at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-ot > Website: http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com From garykjos at gmail.com Wed Jan 23 15:00:34 2008 From: garykjos at gmail.com (Gary Kjos) Date: Wed, 23 Jan 2008 15:00:34 -0600 Subject: [dba-VB] [dba-OT] DBA Award Announcement - Jim Lawrence In-Reply-To: <200801232000.m0NK0Oin003206@databaseadvisors.com> References: <200801232000.m0NK0Oin003206@databaseadvisors.com> Message-ID: Yes, THANK YOU JIM! GK On 1/23/08, John Bartow wrote: > It is with great pleasure that the Board of Directors for Database Advisors, > Inc. presents Jim Lawrence with a Special Service Award in deep appreciation > for all that he has done for Database Advisors as List Master. We value his > dedication, professionalism and the sharing of his talents and we look > forward to continuing our work together. > > http://www.winhaven.net/misc/JimLawrence.htm > > John Bartow, President > Database Advisors, Inc. > Email: mailto:president at databaseadvisors.com > Website: http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-OT mailing list > dba-OT at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-ot > Website: http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com From cfoust at infostatsystems.com Wed Jan 23 15:16:58 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 23 Jan 2008 13:16:58 -0800 Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell In-Reply-To: <200801231958.m0NJwkZF002102@databaseadvisors.com> References: <200801231958.m0NJwkZF002102@databaseadvisors.com> Message-ID: Congratulations, Bryan. No wonder I didn't see this in AccessD!! LOL Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Bartow Sent: Wednesday, January 23, 2008 11:59 AM To: dba-sqlserver at databaseadvisors.com; _DBA-Access; dba-ot at databaseadvisors.com; _DBA-Owners; _DBA-Tech; dba-vb at databaseadvisors.com Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Bryan Carbonell with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 25 05:02:16 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 12:02:16 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of-dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Fri Jan 25 10:23:10 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Fri, 25 Jan 2008 19:23:10 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <001801c85f6e$93a90cb0$6501a8c0@nant> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 25 13:16:09 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:16:09 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil True, and the benchmarks in article shows this too. But for this case with only about 5000 records speed is not important and then I learn something new. It took me a while to find out that you have to use this syntax to create the procedure: CREATE PROCEDURE Something AS EXTERNAL NAME assembly.[namespace.class].method This is for SQL Server 2005 and .Net 2.0. Don't know if it has improved in SQL Server 2008. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From Gustav at cactus.dk Fri Jan 25 13:37:45 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:37:45 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From Gustav at cactus.dk Fri Jan 25 13:54:24 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:54:24 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Located this on the issue: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=95554 /gustav >>> Gustav at cactus.dk 25-01-2008 20:37:45 >>> Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Fri Jan 25 15:09:30 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 26 Jan 2008 00:09:30 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <000601c85f96$93d28680$6501a8c0@nant> Hello Gustav, CLR stored procedures can have output parameters (but not return values) of many different types... There are also CLR Scalar-Valued Functions (SVFs), which return a single value. SVFs can return any scalar type, excluding varchar, char, rowversion, text, ntext, image, timestamp, table, or cursor. This information is from the book: "Professional SQL ServerT 2005 CLR Programming with Stored Procedures, Functions, Triggers, Aggregates, and Types" By Derek Comingore and Douglas Hinson which is very good and covers all(?) the aspects on developing and deploying managed SPs, SVFs, triggers, ... for MS SQL 2005... I haven't yet used SQL 2005 CLR programming - I'm waiting for a customer to request for such programming :) - as far as I see from the book I mentioned above there is no any "black magic" there... BTW, this book has very detailed chapter (Chapter 5) comparing CLR and T-SQL performance - I'd dare to give here an short summary of this chapter: << As it relates to a performance comparison between SQL CLR and T-SQL, we have shown in this chapter that: - String parsing and processing perform better with less CPU resources using CLR base classes. - Computation of even simple proportions performs better in SQL CLR. - SQL CLR table-valued functions can stream results faster to client than T-SQL - T-SQL is still the king of data manipulation, extraction, and updating. >> I haven't seen yet/tried MS SQL 2008 - I will probably do that end of this year if not later... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 10:38 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Sun Jan 27 16:19:23 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 27 Jan 2008 23:19:23 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil Thanks. Looks like a very good reference. /gustav >>> shamil at users.mns.ru 25-01-2008 22:09 >>> Hello Gustav, CLR stored procedures can have output parameters (but not return values) of many different types... There are also CLR Scalar-Valued Functions (SVFs), which return a single value. SVFs can return any scalar type, excluding varchar, char, rowversion, text, ntext, image, timestamp, table, or cursor. This information is from the book: "Professional SQL ServerT 2005 CLR Programming with Stored Procedures, Functions, Triggers, Aggregates, and Types" By Derek Comingore and Douglas Hinson which is very good and covers all(?) the aspects on developing and deploying managed SPs, SVFs, triggers, ... for MS SQL 2005... I haven't yet used SQL 2005 CLR programming - I'm waiting for a customer to request for such programming :) - as far as I see from the book I mentioned above there is no any "black magic" there... BTW, this book has very detailed chapter (Chapter 5) comparing CLR and T-SQL performance - I'd dare to give here an short summary of this chapter: << As it relates to a performance comparison between SQL CLR and T-SQL, we have shown in this chapter that: - String parsing and processing perform better with less CPU resources using CLR base classes. - Computation of even simple proportions performs better in SQL CLR. - SQL CLR table-valued functions can stream results faster to client than T-SQL - T-SQL is still the king of data manipulation, extraction, and updating. >> I haven't seen yet/tried MS SQL 2008 - I will probably do that end of this year if not later... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 10:38 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From djkr at msn.com Sun Jan 27 18:36:37 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:36:37 -0000 Subject: [dba-VB] Performance in disc partitions In-Reply-To: Message-ID: I am about to partition a new disc. One partition will be very active in terms of reads and writes, another almost dormant. Is there any advantage in performance terms in having the active partition as the 'first' one on the disc? Or the last one? It's a long time since I was involved in disc layout at a low level, and I'm wondering whether 'cylinders' these days are still all the same size, with the data near the edge of the platter just more spread out than that near the spindle - or not? TIA John From djkr at msn.com Sun Jan 27 18:46:46 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:46:46 -0000 Subject: [dba-VB] Performance in disc partitions In-Reply-To: Message-ID: Aargh - sorry! I misposted this. It should have been to dba-Tech, where it now is. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of DJK(John) Robinson Sent: 28 January 2008 00:37 To: 'Discussion concerning Visual Basic and related programming issues.' Subject: [dba-VB] Performance in disc partitions I am about to partition a new disc. One partition will be very active in terms of reads and writes, another almost dormant. Is there any advantage in performance terms in having the active partition as the 'first' one on the disc? Or the last one? It's a long time since I was involved in disc layout at a low level, and I'm wondering whether 'cylinders' these days are still all the same size, with the data near the edge of the platter just more spread out than that near the spindle - or not? TIA John _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From djkr at msn.com Sun Jan 27 18:49:29 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:49:29 -0000 Subject: [dba-VB] Recall: Performance in disc partitions Message-ID: The sender would like to recall the message, "Performance in disc partitions". From Gustav at cactus.dk Thu Jan 31 05:25:08 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 31 Jan 2008 12:25:08 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil et al Here is what I did. Some of the data (from some "foreign" apps) are stored in mdb files. These I link to the SQL Server as "linked servers" to be able to import the data to the SQL Server on a regular basis. This is done via some simple queries (no joins, no aggregating) with some basic manipulation writing to similar tables in the server. These queries I can control from Visual Studio. However, VS will not connect directly to a linked server, only to normal databases of the SQL Server. So you will have to connect to such a database and then reference the linked server in a query. One advantage is, that the SQL syntax of such a query is that of SQL Server, not Access/JET. It took some research to locate the syntax for referencing a linked mdb - note the last line in the example here: Select varenr as ItemId, dessnr as DessinNo, case when ( case when isnumeric(right(dessnr, charindex('-', reverse(dessnr)))) <> 0 then convert(bigint, right(dessnr, charindex('-', reverse(dessnr)) - 1)) else 0 end) between 1 and 99 and charindex('-', dessnr) > 0 then rtrim(left( dessnr, len(dessnr) - charindex('-', reverse(dessnr)))) else dessnr end as DessinId >From linkeddb...tblDessin The advantage is, that all that is needed to be set up at the server is the links to the mdb files - the queries are controlled and maintained from VS, and the client apps do not need to know anything about the physical location of the mdb files, neither do they need to establish connections to these. >From this point I can easily store the data in server tables while recording some log details of success or failure. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Thu Jan 31 07:27:19 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 31 Jan 2008 16:27:19 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <002101c8640d$01ae6d20$6501a8c0@nant> Hi Gustav, Yes, I did read about "linked servers", which could be any OLE DB (and ODBC?) data source AFAIK but I have never used them. Please post here some notes later when you get good experience of using them in your test/deployment environments... Thank you. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 31, 2008 2:25 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil et al Here is what I did. Some of the data (from some "foreign" apps) are stored in mdb files. These I link to the SQL Server as "linked servers" to be able to import the data to the SQL Server on a regular basis. This is done via some simple queries (no joins, no aggregating) with some basic manipulation writing to similar tables in the server. These queries I can control from Visual Studio. However, VS will not connect directly to a linked server, only to normal databases of the SQL Server. So you will have to connect to such a database and then reference the linked server in a query. One advantage is, that the SQL syntax of such a query is that of SQL Server, not Access/JET. It took some research to locate the syntax for referencing a linked mdb - note the last line in the example here: Select varenr as ItemId, dessnr as DessinNo, case when ( case when isnumeric(right(dessnr, charindex('-', reverse(dessnr)))) <> 0 then convert(bigint, right(dessnr, charindex('-', reverse(dessnr)) - 1)) else 0 end) between 1 and 99 and charindex('-', dessnr) > 0 then rtrim(left( dessnr, len(dessnr) - charindex('-', reverse(dessnr)))) else dessnr end as DessinId >From linkeddb...tblDessin The advantage is, that all that is needed to be set up at the server is the links to the mdb files - the queries are controlled and maintained from VS, and the client apps do not need to know anything about the physical location of the mdb files, neither do they need to establish connections to these. >From this point I can easily store the data in server tables while recording some log details of success or failure. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From cfoust at infostatsystems.com Wed Jan 2 11:27:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 2 Jan 2008 09:27:26 -0800 Subject: [dba-VB] inheriting events In-Reply-To: <001c01c84bf8$89521650$657aa8c0@M90> References: <001c01c84bf8$89521650$657aa8c0@M90> Message-ID: I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, December 31, 2007 2:00 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] inheriting events I designed a base class which has events: Public Class clsProxyProgress Public Event evProcessName(ByVal strProcessName As String) Public Event evDirectory(ByVal strDirectory As String) Public Event evCurrentFile(ByVal strCurrentFile As String) Public Event evFilesCompleted(ByVal intFilesCompleted As Integer) Public Event evFileCnt(ByVal intFileCnt As Integer) Public Event evRowsCopied(ByVal intRowsCopied As Long) Public Event evStatus(ByVal strStatus As String) I then inherit that class in a child class. Public Class clsCSVDataExportSpec Inherits clsProxyProgress The child class clsCSVDataExportSpec cannot "see" the events in the parent, i.e. it cannot do: RaiseEvent evStatus(mstrStatus) even though its parent class has that event. If I try to do this in the child class I get a compile error. In order to get around this I created functions in the parent class clsProxyProgress Public Sub mStatus(ByVal strStatus As String, ByVal blnStatusReset As Boolean, ByVal blnStatusTimeStamp As Boolean) If blnStatusReset Then mstrStatus = "" If blnStatusTimeStamp Then mstrStatus = mstrStatus & vbCrLf & Now() End If If Len(mstrStatus) > 0 Then mstrStatus = mstrStatus & vbCrLf & strStatus Else mstrStatus = strStatus End If RaiseEvent evStatus(mstrStatus) End Sub NOTICE that in the last line of the sub I raise the evStatus. I then call this sub from the child clsCSVDataExportSpec so that the parent class clsProxyProgress raises the event for the child class. I do this simply because if I try to raise the event up in the parent class directly I get a compile error. The whole point of this stuff is to allow a form to sink events and display data in text boxes on the form. In a form class I dimension a variable for this child class: Private WithEvents fclsCSVDataExport As clsCSVDataExportSpec further down I "sink" the events for this class: Private Sub fclsCSVDataExport_evStatus(ByVal strStatus As String) Handles fclsCSVDataExport.evStatus txtStatus.Text = strStatus Application.DoEvents() End Sub In the "Handles ..." the evStatus is a choice in the intellisense dropdown, IOW this form's module "sees" the event that the child class fclsCSVDataExport inherits from its parent class clsProxyProgress. However the sub fclsCSVDataExport_evStatus() never receives control when the Raisevent is executed. I SUSPECT that the issue is that the "Handles ..." needs to be "Handles fclsProxyProgress", i.e. it needs to "handle" the parent of fclsCSVDataExport, not fclsCSVDataExport itself. fclsCSVDataExport is the actual class that performs the data export for me. clsProxyProgress only exists to allow several different such import / export classes inherit common events and code, and I do that so that I can (eventually) have a generic form that dimensions a clsProxyProgress rather than having a specific import or export class such as clsCSVDataExport or clsCSVDataImport. If anyone is following what I am doing and can point me to how to make this work it would be appreciated. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Wed Jan 2 12:39:33 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 2 Jan 2008 13:39:33 -0500 Subject: [dba-VB] inheriting events In-Reply-To: References: <001c01c84bf8$89521650$657aa8c0@M90> Message-ID: <002b01c84d6e$d1eb76f0$657aa8c0@M90> Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust From shamil at users.mns.ru Thu Jan 3 05:43:20 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 14:43:20 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <002b01c84d6e$d1eb76f0$657aa8c0@M90> Message-ID: <006201c84dfd$d7096180$6501a8c0@nant> Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Thu Jan 3 08:11:29 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 3 Jan 2008 09:11:29 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <006201c84dfd$d7096180$6501a8c0@nant> References: <002b01c84d6e$d1eb76f0$657aa8c0@M90> <006201c84dfd$d7096180$6501a8c0@nant> Message-ID: <001001c84e12$89c24fd0$657aa8c0@M90> Shamil, Thanks for the example code. I have a few questions. 1) What does the interface do, and what do interfaces in general do? It seems that they just force you to implement all of the pieces of something? As such they are a programming tool to enforce consistency and reduce errors due to inadvertently leaving something out? Is that the purpose, or something else, or something more? 2) Does each form have its own UI thread, or do all forms share a thread? 3) How do you implement context switching? I definitely want to use a worker thread for each import / export task, and I want to be able to have a dedicated status form for each task. 4) I use a Application.DoEvents() at the end of each event handler to give the system time to refresh the form so that it will display properly. No idea whether that is really required or not. Is your Sleep(500) just something similar, or is it just to slow things down so that the numbers count slowly? Hmm.. as I stare at the code in bewilderment it slowly sinks in. You are using an implements instead of inheritance so that a) The events can be raised directly in the class that wants to raise them instead of having to call a method up in the parent class to raise the method. Much cleaner and easier. b) The DirectCast has something to cast the object to which states that events will be happening. You do understand that I am barely able to understand what it all does, and in fact probably still do not understand it all. Your code is a nice example of how to do this stuff, thanks for taking the time to put this together. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 6:43 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil From shamil at users.mns.ru Thu Jan 3 08:23:35 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 17:23:35 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <006201c84dfd$d7096180$6501a8c0@nant> Message-ID: <000601c84e14$39f2e030$6501a8c0@nant> Hello John, Here is another version of code, which is more suitable for the subject of this thread - events can't be inherited in .NET AFAIK therefore you have to simulate such inheritance by using base class's wrapper protected methods: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) RaiseEvent EventOne(eventSource.ToString() + ": " + msg) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) RaiseEvent EventTwo(eventSource.ToString() + ": " + msg, count) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 2:43 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Thu Jan 3 08:51:10 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 3 Jan 2008 09:51:10 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <000601c84e14$39f2e030$6501a8c0@nant> References: <006201c84dfd$d7096180$6501a8c0@nant> <000601c84e14$39f2e030$6501a8c0@nant> Message-ID: <001401c84e18$14af6600$657aa8c0@M90> Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 9:24 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hello John, Here is another version of code, which is more suitable for the subject of this thread - events can't be inherited in .NET AFAIK therefore you have to simulate such inheritance by using base class's wrapper protected methods: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) RaiseEvent EventOne(eventSource.ToString() + ": " + msg) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) RaiseEvent EventTwo(eventSource.ToString() + ": " + msg, count) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 2:43 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From shamil at users.mns.ru Thu Jan 3 09:05:39 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 18:05:39 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <001001c84e12$89c24fd0$657aa8c0@M90> Message-ID: <000801c84e1a$1a8e51b0$6501a8c0@nant> Hi John, 1. Interfaces Interfaces allow having low coupled still compile time bound (i.e. for sure syntactically correct) code... I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... 2) Yes, every winform has its own UI thread AFAIK 3) Context switching - I have to spend some time making sample solution for that for Winforms - I do not program WinForms apps these days, only ASP.NET. I can do that sample code tomorrow probably. If you're in hurry here is a good source about what have to be done: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 4) Application.DoEvents() - I'd never rely on it. The Sleep(...) I use is just for sample purposes to simulate some work, not to let event to be raised /processed. If you will use context switching then you'll always get correctly updated winform and its controls... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:11 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, Thanks for the example code. I have a few questions. 1) What does the interface do, and what do interfaces in general do? It seems that they just force you to implement all of the pieces of something? As such they are a programming tool to enforce consistency and reduce errors due to inadvertently leaving something out? Is that the purpose, or something else, or something more? 2) Does each form have its own UI thread, or do all forms share a thread? 3) How do you implement context switching? I definitely want to use a worker thread for each import / export task, and I want to be able to have a dedicated status form for each task. 4) I use a Application.DoEvents() at the end of each event handler to give the system time to refresh the form so that it will display properly. No idea whether that is really required or not. Is your Sleep(500) just something similar, or is it just to slow things down so that the numbers count slowly? Hmm.. as I stare at the code in bewilderment it slowly sinks in. You are using an implements instead of inheritance so that a) The events can be raised directly in the class that wants to raise them instead of having to call a method up in the parent class to raise the method. Much cleaner and easier. b) The DirectCast has something to cast the object to which states that events will be happening. You do understand that I am barely able to understand what it all does, and in fact probably still do not understand it all. Your code is a nice example of how to do this stuff, thanks for taking the time to put this together. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 6:43 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Jan 3 09:33:14 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 03 Jan 2008 16:33:14 +0100 Subject: [dba-VB] inheriting events Message-ID: Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined-from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... From shamil at users.mns.ru Thu Jan 3 11:47:29 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 20:47:29 +0300 Subject: [dba-VB] inheriting events In-Reply-To: Message-ID: <000001c84e30$b5949730$6501a8c0@nant> Hi Gustav, Please do not frame "these golden words" :) I mean it's of course better to have all these principles in one's active set of best programming practices... If you frame "these golden words" somebody may think I'm a kind of "preaching for ignorance", and I'm not I think.... Thanks. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 03, 2008 6:33 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 4 06:02:34 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 04 Jan 2008 13:02:34 +0100 Subject: [dba-VB] inheriting events Message-ID: Hi Shamil Rest assured, I do keep them in my head - in fact I think I've always worked this way without feeling ignorant. /gustav >>> shamil at users.mns.ru 03-01-2008 18:47 >>> Hi Gustav, Please do not frame "these golden words" :) I mean it's of course better to have all these principles in one's active set of best programming practices... If you frame "these golden words" somebody may think I'm a kind of "preaching for ignorance", and I'm not I think.... Thanks. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 03, 2008 6:33 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... From shamil at users.mns.ru Fri Jan 4 18:49:11 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 5 Jan 2008 03:49:11 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <001401c84e18$14af6600$657aa8c0@M90> Message-ID: <000001c84f34$c9503630$6501a8c0@nant> Hello John, As promised yesterday - here is a solution with multi-threading based on article I mentioned in this thread already: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 1. Create WinForms sample app with Form1 form 2. Create two buttons Button1 and Button2 on this form 3. Create listbox ListBox1 4. Put this code behind for Form1 and set buttons' click event properly: Public Class Form1 : Implements IStatusDisplay Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() TestModule.MainSync(Me) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() TestModule.MainAsync(Me) End Sub Delegate Sub StringParameterDelegate(ByVal value As String) Public Sub UpdateStatus(ByVal value As String) _ Implements IStatusDisplay.UpdateStatus If (Me.InvokeRequired) Then Me.BeginInvoke(New StringParameterDelegate( _ AddressOf UpdateStatus), New Object() {value}) Return End If ListBox1.Items.Add(value) Application.DoEvents() End Sub End Class 5. put this code into Module1 Option Explicit On Public Interface IStatusDisplay Sub UpdateStatus(ByVal value As String) End Interface Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Protected _display As IStatusDisplay Public Sub New(ByVal display As IStatusDisplay) _display = display End Sub Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventOne(message) _display.UpdateStatus(message) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventTwo(message, count) _display.UpdateStatus(message + ", count=" + count.ToString()) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub MainSync(ByVal display As IStatusDisplay) ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test 'MainAsync() End Sub Sub MainAsync(ByVal display As IStatusDisplay) Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module Enjoy multi-threading! :) If you find bugs please post fixes here. Thanks. -- Shamil P.S. Notes: 1. Watch line wraps in the code above 2. I did leave Console.WriteLine(...) in the above code to see how yesterday's console app code was refactored into winforms code - as you can find that weren't many changes... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:51 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Fri Jan 4 18:53:32 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 4 Jan 2008 19:53:32 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <000001c84f34$c9503630$6501a8c0@nant> References: <001401c84e18$14af6600$657aa8c0@M90> <000001c84f34$c9503630$6501a8c0@nant> Message-ID: <005901c84f35$651c65c0$657aa8c0@M90> Thanks Shamil. I'll absorb this and see how I can apply it to my code. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Friday, January 04, 2008 7:49 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hello John, As promised yesterday - here is a solution with multi-threading based on article I mentioned in this thread already: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 1. Create WinForms sample app with Form1 form 2. Create two buttons Button1 and Button2 on this form 3. Create listbox ListBox1 4. Put this code behind for Form1 and set buttons' click event properly: Public Class Form1 : Implements IStatusDisplay Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() TestModule.MainSync(Me) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() TestModule.MainAsync(Me) End Sub Delegate Sub StringParameterDelegate(ByVal value As String) Public Sub UpdateStatus(ByVal value As String) _ Implements IStatusDisplay.UpdateStatus If (Me.InvokeRequired) Then Me.BeginInvoke(New StringParameterDelegate( _ AddressOf UpdateStatus), New Object() {value}) Return End If ListBox1.Items.Add(value) Application.DoEvents() End Sub End Class 5. put this code into Module1 Option Explicit On Public Interface IStatusDisplay Sub UpdateStatus(ByVal value As String) End Interface Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Protected _display As IStatusDisplay Public Sub New(ByVal display As IStatusDisplay) _display = display End Sub Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventOne(message) _display.UpdateStatus(message) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventTwo(message, count) _display.UpdateStatus(message + ", count=" + count.ToString()) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub MainSync(ByVal display As IStatusDisplay) ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test 'MainAsync() End Sub Sub MainAsync(ByVal display As IStatusDisplay) Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module Enjoy multi-threading! :) If you find bugs please post fixes here. Thanks. -- Shamil P.S. Notes: 1. Watch line wraps in the code above 2. I did leave Console.WriteLine(...) in the above code to see how yesterday's console app code was refactored into winforms code - as you can find that weren't many changes... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:51 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Jan 10 11:18:32 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 10 Jan 2008 18:18:32 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From cfoust at infostatsystems.com Thu Jan 10 14:31:29 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 10 Jan 2008 12:31:29 -0800 Subject: [dba-VB] Compiling Class Library In-Reply-To: References: Message-ID: I don't know if you CAN get rid of the message. You can't run a class library or any class directly, so the message is accurate. You're editing a class library referenced in the other solution/project you have open and trying to immediately reflect those changes. I stopped trying that after the first time. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 9:19 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From R.Griffiths at bury.gov.uk Fri Jan 11 03:06:56 2008 From: R.Griffiths at bury.gov.uk (Griffiths, Richard) Date: Fri, 11 Jan 2008 09:06:56 -0000 Subject: [dba-VB] Compiling Class Library In-Reply-To: References: Message-ID: <200801110850.m0B8oDO11368@smarthost.yourcomms.net> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com ----------------------------------------------------------------- Why not visit our website www.bury.gov.uk ----------------------------------------------------------------- The information contained in this e-mail and any files transmitted with it is for the intended recipient(s) alone. It may contain confidential information that is exempt from the disclosure under English law and may also be covered by legal,professional or other privilege. If you are not the intended recipient, you must not copy, distribute or take any action in reliance on it. If you have received this e-mail in error, please notify us immediately by using the reply facility on your e-mail system. If this message is being transmitted over the Internet, be aware that it may be intercepted by third parties. As a public body, the Council may be required to disclose this e-mail or any response to it under the Freedom of Information Act 2000 unless the information in it is covered by one of the exemptions in the Act. By responding to this e-mail you accept that your response may be subject of recording/monitoring to ensure compliance with the Council's ICT Security Policy. Electronic service accepted only at legalservices at bury.gov.uk and on fax number 0161 253 5119 . ************************************************************* From Gustav at cactus.dk Fri Jan 11 08:29:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 15:29:41 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Charlotte True, but I had to do some debugging which required minor changes to the library which, by the way, is not used by any other project. /gustav >>> cfoust at infostatsystems.com 10-01-2008 21:31:29 >>> I don't know if you CAN get rid of the message. You can't run a class library or any class directly, so the message is accurate. You're editing a class library referenced in the other solution/project you have open and trying to immediately reflect those changes. I stopped trying that after the first time. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 9:19 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From Gustav at cactus.dk Fri Jan 11 08:55:47 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 15:55:47 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Richard OK, that makes sense. But how? If I open Add Reference I have tabs: .NET, COM, Projects, Browse, Recent However, tab Projects is empty. Now, I can add the Class Library as a project, and that causes the main project to be wrapped in a Solution given the name of the main project. Then, if I open Add Reference for either project (main or library), the other project is listed as a reference. Is this what I should do? /gustav >>> R.Griffiths at bury.gov.uk 11-01-2008 10:06:56 >>> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From shamil at users.mns.ru Fri Jan 11 09:35:49 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Fri, 11 Jan 2008 18:35:49 +0300 Subject: [dba-VB] Compiling Class Library In-Reply-To: Message-ID: <000001c85467$a48910f0$6401a8c0@nant> Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 11 10:13:10 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 17:13:10 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Richard Small correction: Then, if I open Add Reference for either project (main or library), the other project is listed as a possible reference. /gustav >>> Gustav at cactus.dk 11-01-2008 15:55:47 >>> Hi Richard OK, that makes sense. But how? If I open Add Reference I have tabs: .NET, COM, Projects, Browse, Recent However, tab Projects is empty. Now, I can add the Class Library as a project, and that causes the main project to be wrapped in a Solution given the name of the main project. Then, if I open Add Reference for either project (main or library), the other project is listed as a reference. Is this what I should do? /gustav >>> R.Griffiths at bury.gov.uk 11-01-2008 10:06:56 >>> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From cfoust at infostatsystems.com Fri Jan 11 10:13:25 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 11 Jan 2008 08:13:25 -0800 Subject: [dba-VB] Compiling Class Library In-Reply-To: <000001c85467$a48910f0$6401a8c0@nant> References: <000001c85467$a48910f0$6401a8c0@nant> Message-ID: Yes, that's the way we build ours too. Our apps are solutions that contain multiple projects, some of which are shared with our other apps. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Friday, January 11, 2008 7:36 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Compiling Class Library Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 11 10:29:03 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 17:29:03 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Shamil and Charlotte The scenario you and Charlotte describe seems to be the right way to do it when the classlibs are under your control. What I did originally was to reference the compiled dll, and I guess there really is no reason to do so unless you don't have the source available. Then, when referencing the dll of the classlib, (re)building the classlib doesn't seem to push the changes to the main project. I agree with Shamil that VS is great. The more you work with it the more you appreciate it and all its features and how well they are thought out ... /gustav >>> shamil at users.mns.ru 11-01-2008 16:35:49 >>> Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From john at winhaven.net Wed Jan 23 13:58:52 2008 From: john at winhaven.net (John Bartow) Date: Wed, 23 Jan 2008 13:58:52 -0600 Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell Message-ID: <200801231958.m0NJwkZF002102@databaseadvisors.com> It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Bryan Carbonell with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com From john at winhaven.net Wed Jan 23 14:00:27 2008 From: john at winhaven.net (John Bartow) Date: Wed, 23 Jan 2008 14:00:27 -0600 Subject: [dba-VB] DBA Award Announcement - Jim Lawrence Message-ID: <200801232000.m0NK0Oin003206@databaseadvisors.com> It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Jim Lawrence with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. http://www.winhaven.net/misc/JimLawrence.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com From garykjos at gmail.com Wed Jan 23 14:59:50 2008 From: garykjos at gmail.com (Gary Kjos) Date: Wed, 23 Jan 2008 14:59:50 -0600 Subject: [dba-VB] [dba-OT] DBA Award Announcement - Bryan Carbonnell In-Reply-To: <200801231958.m0NJwkZF002102@databaseadvisors.com> References: <200801231958.m0NJwkZF002102@databaseadvisors.com> Message-ID: Yes, THANK YOU BRYAN! GK On 1/23/08, John Bartow wrote: > It is with great pleasure that the Board of Directors for Database Advisors, > Inc. presents Bryan Carbonell with a Special Service Award in deep > appreciation for all that he has done for Database Advisors as List Master. > We value his dedication, professionalism and the sharing of his talents and > we look forward to continuing our work together. > > Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm > > John Bartow, President > Database Advisors, Inc. > Email: mailto:president at databaseadvisors.com > Website: http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-OT mailing list > dba-OT at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-ot > Website: http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com From garykjos at gmail.com Wed Jan 23 15:00:34 2008 From: garykjos at gmail.com (Gary Kjos) Date: Wed, 23 Jan 2008 15:00:34 -0600 Subject: [dba-VB] [dba-OT] DBA Award Announcement - Jim Lawrence In-Reply-To: <200801232000.m0NK0Oin003206@databaseadvisors.com> References: <200801232000.m0NK0Oin003206@databaseadvisors.com> Message-ID: Yes, THANK YOU JIM! GK On 1/23/08, John Bartow wrote: > It is with great pleasure that the Board of Directors for Database Advisors, > Inc. presents Jim Lawrence with a Special Service Award in deep appreciation > for all that he has done for Database Advisors as List Master. We value his > dedication, professionalism and the sharing of his talents and we look > forward to continuing our work together. > > http://www.winhaven.net/misc/JimLawrence.htm > > John Bartow, President > Database Advisors, Inc. > Email: mailto:president at databaseadvisors.com > Website: http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-OT mailing list > dba-OT at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-ot > Website: http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com From cfoust at infostatsystems.com Wed Jan 23 15:16:58 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 23 Jan 2008 13:16:58 -0800 Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell In-Reply-To: <200801231958.m0NJwkZF002102@databaseadvisors.com> References: <200801231958.m0NJwkZF002102@databaseadvisors.com> Message-ID: Congratulations, Bryan. No wonder I didn't see this in AccessD!! LOL Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Bartow Sent: Wednesday, January 23, 2008 11:59 AM To: dba-sqlserver at databaseadvisors.com; _DBA-Access; dba-ot at databaseadvisors.com; _DBA-Owners; _DBA-Tech; dba-vb at databaseadvisors.com Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Bryan Carbonell with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 25 05:02:16 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 12:02:16 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of-dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Fri Jan 25 10:23:10 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Fri, 25 Jan 2008 19:23:10 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <001801c85f6e$93a90cb0$6501a8c0@nant> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 25 13:16:09 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:16:09 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil True, and the benchmarks in article shows this too. But for this case with only about 5000 records speed is not important and then I learn something new. It took me a while to find out that you have to use this syntax to create the procedure: CREATE PROCEDURE Something AS EXTERNAL NAME assembly.[namespace.class].method This is for SQL Server 2005 and .Net 2.0. Don't know if it has improved in SQL Server 2008. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From Gustav at cactus.dk Fri Jan 25 13:37:45 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:37:45 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From Gustav at cactus.dk Fri Jan 25 13:54:24 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:54:24 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Located this on the issue: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=95554 /gustav >>> Gustav at cactus.dk 25-01-2008 20:37:45 >>> Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Fri Jan 25 15:09:30 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 26 Jan 2008 00:09:30 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <000601c85f96$93d28680$6501a8c0@nant> Hello Gustav, CLR stored procedures can have output parameters (but not return values) of many different types... There are also CLR Scalar-Valued Functions (SVFs), which return a single value. SVFs can return any scalar type, excluding varchar, char, rowversion, text, ntext, image, timestamp, table, or cursor. This information is from the book: "Professional SQL ServerT 2005 CLR Programming with Stored Procedures, Functions, Triggers, Aggregates, and Types" By Derek Comingore and Douglas Hinson which is very good and covers all(?) the aspects on developing and deploying managed SPs, SVFs, triggers, ... for MS SQL 2005... I haven't yet used SQL 2005 CLR programming - I'm waiting for a customer to request for such programming :) - as far as I see from the book I mentioned above there is no any "black magic" there... BTW, this book has very detailed chapter (Chapter 5) comparing CLR and T-SQL performance - I'd dare to give here an short summary of this chapter: << As it relates to a performance comparison between SQL CLR and T-SQL, we have shown in this chapter that: - String parsing and processing perform better with less CPU resources using CLR base classes. - Computation of even simple proportions performs better in SQL CLR. - SQL CLR table-valued functions can stream results faster to client than T-SQL - T-SQL is still the king of data manipulation, extraction, and updating. >> I haven't seen yet/tried MS SQL 2008 - I will probably do that end of this year if not later... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 10:38 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Sun Jan 27 16:19:23 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 27 Jan 2008 23:19:23 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil Thanks. Looks like a very good reference. /gustav >>> shamil at users.mns.ru 25-01-2008 22:09 >>> Hello Gustav, CLR stored procedures can have output parameters (but not return values) of many different types... There are also CLR Scalar-Valued Functions (SVFs), which return a single value. SVFs can return any scalar type, excluding varchar, char, rowversion, text, ntext, image, timestamp, table, or cursor. This information is from the book: "Professional SQL ServerT 2005 CLR Programming with Stored Procedures, Functions, Triggers, Aggregates, and Types" By Derek Comingore and Douglas Hinson which is very good and covers all(?) the aspects on developing and deploying managed SPs, SVFs, triggers, ... for MS SQL 2005... I haven't yet used SQL 2005 CLR programming - I'm waiting for a customer to request for such programming :) - as far as I see from the book I mentioned above there is no any "black magic" there... BTW, this book has very detailed chapter (Chapter 5) comparing CLR and T-SQL performance - I'd dare to give here an short summary of this chapter: << As it relates to a performance comparison between SQL CLR and T-SQL, we have shown in this chapter that: - String parsing and processing perform better with less CPU resources using CLR base classes. - Computation of even simple proportions performs better in SQL CLR. - SQL CLR table-valued functions can stream results faster to client than T-SQL - T-SQL is still the king of data manipulation, extraction, and updating. >> I haven't seen yet/tried MS SQL 2008 - I will probably do that end of this year if not later... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 10:38 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From djkr at msn.com Sun Jan 27 18:36:37 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:36:37 -0000 Subject: [dba-VB] Performance in disc partitions In-Reply-To: Message-ID: I am about to partition a new disc. One partition will be very active in terms of reads and writes, another almost dormant. Is there any advantage in performance terms in having the active partition as the 'first' one on the disc? Or the last one? It's a long time since I was involved in disc layout at a low level, and I'm wondering whether 'cylinders' these days are still all the same size, with the data near the edge of the platter just more spread out than that near the spindle - or not? TIA John From djkr at msn.com Sun Jan 27 18:46:46 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:46:46 -0000 Subject: [dba-VB] Performance in disc partitions In-Reply-To: Message-ID: Aargh - sorry! I misposted this. It should have been to dba-Tech, where it now is. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of DJK(John) Robinson Sent: 28 January 2008 00:37 To: 'Discussion concerning Visual Basic and related programming issues.' Subject: [dba-VB] Performance in disc partitions I am about to partition a new disc. One partition will be very active in terms of reads and writes, another almost dormant. Is there any advantage in performance terms in having the active partition as the 'first' one on the disc? Or the last one? It's a long time since I was involved in disc layout at a low level, and I'm wondering whether 'cylinders' these days are still all the same size, with the data near the edge of the platter just more spread out than that near the spindle - or not? TIA John _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From djkr at msn.com Sun Jan 27 18:49:29 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:49:29 -0000 Subject: [dba-VB] Recall: Performance in disc partitions Message-ID: The sender would like to recall the message, "Performance in disc partitions". From Gustav at cactus.dk Thu Jan 31 05:25:08 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 31 Jan 2008 12:25:08 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil et al Here is what I did. Some of the data (from some "foreign" apps) are stored in mdb files. These I link to the SQL Server as "linked servers" to be able to import the data to the SQL Server on a regular basis. This is done via some simple queries (no joins, no aggregating) with some basic manipulation writing to similar tables in the server. These queries I can control from Visual Studio. However, VS will not connect directly to a linked server, only to normal databases of the SQL Server. So you will have to connect to such a database and then reference the linked server in a query. One advantage is, that the SQL syntax of such a query is that of SQL Server, not Access/JET. It took some research to locate the syntax for referencing a linked mdb - note the last line in the example here: Select varenr as ItemId, dessnr as DessinNo, case when ( case when isnumeric(right(dessnr, charindex('-', reverse(dessnr)))) <> 0 then convert(bigint, right(dessnr, charindex('-', reverse(dessnr)) - 1)) else 0 end) between 1 and 99 and charindex('-', dessnr) > 0 then rtrim(left( dessnr, len(dessnr) - charindex('-', reverse(dessnr)))) else dessnr end as DessinId >From linkeddb...tblDessin The advantage is, that all that is needed to be set up at the server is the links to the mdb files - the queries are controlled and maintained from VS, and the client apps do not need to know anything about the physical location of the mdb files, neither do they need to establish connections to these. >From this point I can easily store the data in server tables while recording some log details of success or failure. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Thu Jan 31 07:27:19 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 31 Jan 2008 16:27:19 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <002101c8640d$01ae6d20$6501a8c0@nant> Hi Gustav, Yes, I did read about "linked servers", which could be any OLE DB (and ODBC?) data source AFAIK but I have never used them. Please post here some notes later when you get good experience of using them in your test/deployment environments... Thank you. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 31, 2008 2:25 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil et al Here is what I did. Some of the data (from some "foreign" apps) are stored in mdb files. These I link to the SQL Server as "linked servers" to be able to import the data to the SQL Server on a regular basis. This is done via some simple queries (no joins, no aggregating) with some basic manipulation writing to similar tables in the server. These queries I can control from Visual Studio. However, VS will not connect directly to a linked server, only to normal databases of the SQL Server. So you will have to connect to such a database and then reference the linked server in a query. One advantage is, that the SQL syntax of such a query is that of SQL Server, not Access/JET. It took some research to locate the syntax for referencing a linked mdb - note the last line in the example here: Select varenr as ItemId, dessnr as DessinNo, case when ( case when isnumeric(right(dessnr, charindex('-', reverse(dessnr)))) <> 0 then convert(bigint, right(dessnr, charindex('-', reverse(dessnr)) - 1)) else 0 end) between 1 and 99 and charindex('-', dessnr) > 0 then rtrim(left( dessnr, len(dessnr) - charindex('-', reverse(dessnr)))) else dessnr end as DessinId >From linkeddb...tblDessin The advantage is, that all that is needed to be set up at the server is the links to the mdb files - the queries are controlled and maintained from VS, and the client apps do not need to know anything about the physical location of the mdb files, neither do they need to establish connections to these. >From this point I can easily store the data in server tables while recording some log details of success or failure. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From cfoust at infostatsystems.com Wed Jan 2 11:27:26 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 2 Jan 2008 09:27:26 -0800 Subject: [dba-VB] inheriting events In-Reply-To: <001c01c84bf8$89521650$657aa8c0@M90> References: <001c01c84bf8$89521650$657aa8c0@M90> Message-ID: I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Monday, December 31, 2007 2:00 PM To: dba-vb at databaseadvisors.com Subject: [dba-VB] inheriting events I designed a base class which has events: Public Class clsProxyProgress Public Event evProcessName(ByVal strProcessName As String) Public Event evDirectory(ByVal strDirectory As String) Public Event evCurrentFile(ByVal strCurrentFile As String) Public Event evFilesCompleted(ByVal intFilesCompleted As Integer) Public Event evFileCnt(ByVal intFileCnt As Integer) Public Event evRowsCopied(ByVal intRowsCopied As Long) Public Event evStatus(ByVal strStatus As String) I then inherit that class in a child class. Public Class clsCSVDataExportSpec Inherits clsProxyProgress The child class clsCSVDataExportSpec cannot "see" the events in the parent, i.e. it cannot do: RaiseEvent evStatus(mstrStatus) even though its parent class has that event. If I try to do this in the child class I get a compile error. In order to get around this I created functions in the parent class clsProxyProgress Public Sub mStatus(ByVal strStatus As String, ByVal blnStatusReset As Boolean, ByVal blnStatusTimeStamp As Boolean) If blnStatusReset Then mstrStatus = "" If blnStatusTimeStamp Then mstrStatus = mstrStatus & vbCrLf & Now() End If If Len(mstrStatus) > 0 Then mstrStatus = mstrStatus & vbCrLf & strStatus Else mstrStatus = strStatus End If RaiseEvent evStatus(mstrStatus) End Sub NOTICE that in the last line of the sub I raise the evStatus. I then call this sub from the child clsCSVDataExportSpec so that the parent class clsProxyProgress raises the event for the child class. I do this simply because if I try to raise the event up in the parent class directly I get a compile error. The whole point of this stuff is to allow a form to sink events and display data in text boxes on the form. In a form class I dimension a variable for this child class: Private WithEvents fclsCSVDataExport As clsCSVDataExportSpec further down I "sink" the events for this class: Private Sub fclsCSVDataExport_evStatus(ByVal strStatus As String) Handles fclsCSVDataExport.evStatus txtStatus.Text = strStatus Application.DoEvents() End Sub In the "Handles ..." the evStatus is a choice in the intellisense dropdown, IOW this form's module "sees" the event that the child class fclsCSVDataExport inherits from its parent class clsProxyProgress. However the sub fclsCSVDataExport_evStatus() never receives control when the Raisevent is executed. I SUSPECT that the issue is that the "Handles ..." needs to be "Handles fclsProxyProgress", i.e. it needs to "handle" the parent of fclsCSVDataExport, not fclsCSVDataExport itself. fclsCSVDataExport is the actual class that performs the data export for me. clsProxyProgress only exists to allow several different such import / export classes inherit common events and code, and I do that so that I can (eventually) have a generic form that dimensions a clsProxyProgress rather than having a specific import or export class such as clsCSVDataExport or clsCSVDataImport. If anyone is following what I am doing and can point me to how to make this work it would be appreciated. Thanks, John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Wed Jan 2 12:39:33 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Wed, 2 Jan 2008 13:39:33 -0500 Subject: [dba-VB] inheriting events In-Reply-To: References: <001c01c84bf8$89521650$657aa8c0@M90> Message-ID: <002b01c84d6e$d1eb76f0$657aa8c0@M90> Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust From shamil at users.mns.ru Thu Jan 3 05:43:20 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 14:43:20 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <002b01c84d6e$d1eb76f0$657aa8c0@M90> Message-ID: <006201c84dfd$d7096180$6501a8c0@nant> Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Thu Jan 3 08:11:29 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 3 Jan 2008 09:11:29 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <006201c84dfd$d7096180$6501a8c0@nant> References: <002b01c84d6e$d1eb76f0$657aa8c0@M90> <006201c84dfd$d7096180$6501a8c0@nant> Message-ID: <001001c84e12$89c24fd0$657aa8c0@M90> Shamil, Thanks for the example code. I have a few questions. 1) What does the interface do, and what do interfaces in general do? It seems that they just force you to implement all of the pieces of something? As such they are a programming tool to enforce consistency and reduce errors due to inadvertently leaving something out? Is that the purpose, or something else, or something more? 2) Does each form have its own UI thread, or do all forms share a thread? 3) How do you implement context switching? I definitely want to use a worker thread for each import / export task, and I want to be able to have a dedicated status form for each task. 4) I use a Application.DoEvents() at the end of each event handler to give the system time to refresh the form so that it will display properly. No idea whether that is really required or not. Is your Sleep(500) just something similar, or is it just to slow things down so that the numbers count slowly? Hmm.. as I stare at the code in bewilderment it slowly sinks in. You are using an implements instead of inheritance so that a) The events can be raised directly in the class that wants to raise them instead of having to call a method up in the parent class to raise the method. Much cleaner and easier. b) The DirectCast has something to cast the object to which states that events will be happening. You do understand that I am barely able to understand what it all does, and in fact probably still do not understand it all. Your code is a nice example of how to do this stuff, thanks for taking the time to put this together. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 6:43 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil From shamil at users.mns.ru Thu Jan 3 08:23:35 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 17:23:35 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <006201c84dfd$d7096180$6501a8c0@nant> Message-ID: <000601c84e14$39f2e030$6501a8c0@nant> Hello John, Here is another version of code, which is more suitable for the subject of this thread - events can't be inherited in .NET AFAIK therefore you have to simulate such inheritance by using base class's wrapper protected methods: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) RaiseEvent EventOne(eventSource.ToString() + ": " + msg) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) RaiseEvent EventTwo(eventSource.ToString() + ": " + msg, count) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 2:43 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Thu Jan 3 08:51:10 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Thu, 3 Jan 2008 09:51:10 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <000601c84e14$39f2e030$6501a8c0@nant> References: <006201c84dfd$d7096180$6501a8c0@nant> <000601c84e14$39f2e030$6501a8c0@nant> Message-ID: <001401c84e18$14af6600$657aa8c0@M90> Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 9:24 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hello John, Here is another version of code, which is more suitable for the subject of this thread - events can't be inherited in .NET AFAIK therefore you have to simulate such inheritance by using base class's wrapper protected methods: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) RaiseEvent EventOne(eventSource.ToString() + ": " + msg) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) RaiseEvent EventTwo(eventSource.ToString() + ": " + msg, count) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 2:43 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Wednesday, January 02, 2008 9:40 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Sorry guys, I figured it out. Basically I have a base class (clsProxyProgress) whose sole reason for its existence is to raise events for derived classes. I have one (at the moment) derived class (clsCSVDataExportSpec) which can then use its parent clsProxyProgress to raise events for it. clsCSVDataExportSpec supervises EXPORTING data. I have a frmProxyProgress whose sole purpose is to sink the events raised via clsProxyProgress and display progress data for classes derived from clsProxyProgress - clsCSVDataExportSpec in this case. IOW it is clsCSVDataExportSpec that wants to display status information, and it does so via clsProxyProgress (its parent). I have a supervisor class that creates instances of clsCSVDataExportSpec. I may have 1 or 5 different CSV Exports happening, and the supervisor class loads and starts them running. These instances of clsCSVDataExportSpec are run periodically which is why there may be 1 or N, it just depends on whether it is time to run a specific instance. Each instance of clsCSVDataExportSpec gets data that tells it whether or not to open a display form frmProxyProgress to display its progress in. clsCSVDataExportSpec does not NEED a progress form in order to function, it simply displays its progress data in a frmProxyProgress instance if it is told to do so. In fact it simply INSTANTIATES a frmProxyProgress if it is told to do so. It always raises the events that would be displayed in frmProxyProgress even if it does not have a display form open to use. clsProxyProgress and frmProxyProgress can also be used for clsCSVDataImportSpec. clsCSVDataImportSpec is a class which supervises IMPORTING data. There may be 1 or N copies of clsCSVDataImportSpec. Likewise clsCSVDataImportSpec can be told to display it's progress in an instance of frmProxyProgress. There are also two flat file process classes that can use clsProxyProgress and frmProxyProgress. Each of them can have 1 or N instances running. As you can see there can be nothing running or there can be a dozen different CSV or FlatFile imports or exports running, all at the "same" time. Each can display a progress or not. So the point here is that by creating clsProxyProgress and frmProxyProgress, I have a form that sinks events from clsProxyProgress, and four different Flat/CSV Import/Export classes that inherit clsProxyProgress. Because they all inherit the same class, they can all raise the same events up in the base class, but more importantly I now have just one proxy class and one proxy form that handles all of the raising / sinking of these events and displaying the status in form instances. The key to get it all working is that I needed to know that I could pass a derived class into a declaration of a base class in the New() sub. In the proxy FORM: ' 'Dimension a base class variable WithEvents ' private WithEvents mclsProxyProgress as clsProxyProgress ' 'In New() receive a base class instance ' sub new( lclsProxyProgress as clsProxyProgress) ' 'Set the module level variable = to the instance pointer passed in to new() ' mclsProxyProgress = lclsProxyProgress end sub ' 'Sink events for the base class here and perform some action (display a status for example) ' sub mslcProxyProgress_SomeEventSink(strStatus as string) txtStatus.text = strStatus end sub In the base class: ' 'Dimension a form variable to use to display the status ' private mfrmDisplay as form ' 'Open a form and pass in a pointer to me ' sub OpenDisplayForm() set mfrmDisplay = new frmProxyProgress(me) frmProxyProgress.Show end sub NOTICE that I passed in a pointer to the DERIVED class but the form's New() expects a variable of the Base class. That works, and that is what I was stumbling over. I did not realize that VB.Net would dynamically cast a derived class into a base class in this fashion. With all this in place, I can have 1 to N instances of many different derived classes (siblings) of the base class clsProxyProgress. All the derived classes (siblings) can use the same form (but not the same INSTANCE of that form) to display its progress. Each instance of a derived class can have its own instance of a status form and display its status in that form instance. Sometimes when I don't understand what I am doing, I can't explain what I don't understand well enough to get help in understanding it. Or MAYBE (as William is wont to say) I am just obtuse. I think I now need to go back into the base class and declare it MustInherit and declare all of the methods ... uh... friend? Or protected? Another thing that I do not understand at all really. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte Foust Sent: Wednesday, January 02, 2008 12:27 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events I'm not sure I understand what you're trying to do, John. Your clsdDSVDataExportSpec inherits the methods and properties of the class clsProxyProgress, it doesn't inherit things happening to clsProxyProgress. We have a TransferHelper class which doesn't inherit anything. We have classes for Import and Export that are declared as Public MustInherit, with all their methods and properties declared as protected. Then we have specific transfer method classes that inherit the MustInherit classes and that handle the specific operations required for a particular type of import or export. The TransferHelper class has shared methods and properties, so we can call them by code like TransferHelper.ImportCSV(args). I don't see what you're trying to do by raising a "status" event. Are you logging the work? We use a separte EventLogItem class to wrap the creation of event log items. Charlotte Foust _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From shamil at users.mns.ru Thu Jan 3 09:05:39 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 18:05:39 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <001001c84e12$89c24fd0$657aa8c0@M90> Message-ID: <000801c84e1a$1a8e51b0$6501a8c0@nant> Hi John, 1. Interfaces Interfaces allow having low coupled still compile time bound (i.e. for sure syntactically correct) code... I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... 2) Yes, every winform has its own UI thread AFAIK 3) Context switching - I have to spend some time making sample solution for that for Winforms - I do not program WinForms apps these days, only ASP.NET. I can do that sample code tomorrow probably. If you're in hurry here is a good source about what have to be done: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 4) Application.DoEvents() - I'd never rely on it. The Sleep(...) I use is just for sample purposes to simulate some work, not to let event to be raised /processed. If you will use context switching then you'll always get correctly updated winform and its controls... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:11 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, Thanks for the example code. I have a few questions. 1) What does the interface do, and what do interfaces in general do? It seems that they just force you to implement all of the pieces of something? As such they are a programming tool to enforce consistency and reduce errors due to inadvertently leaving something out? Is that the purpose, or something else, or something more? 2) Does each form have its own UI thread, or do all forms share a thread? 3) How do you implement context switching? I definitely want to use a worker thread for each import / export task, and I want to be able to have a dedicated status form for each task. 4) I use a Application.DoEvents() at the end of each event handler to give the system time to refresh the form so that it will display properly. No idea whether that is really required or not. Is your Sleep(500) just something similar, or is it just to slow things down so that the numbers count slowly? Hmm.. as I stare at the code in bewilderment it slowly sinks in. You are using an implements instead of inheritance so that a) The events can be raised directly in the class that wants to raise them instead of having to call a method up in the parent class to raise the method. Much cleaner and easier. b) The DirectCast has something to cast the object to which states that events will be happening. You do understand that I am barely able to understand what it all does, and in fact probably still do not understand it all. Your code is a nice example of how to do this stuff, thanks for taking the time to put this together. ;-) John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Thursday, January 03, 2008 6:43 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi John, Have a look below is the code you can use and generalize even more still keeping it very simple. In fact there are two samples in this code: synchronous and asynchronous - both work well in console mode as you can find. But the second async one has to be changed to be used with WinForms because WinForms have their own UI thread, and to call that thread properly from worker threads thread context switching has to be implemented.... HTH, Shamil P.S. Code: Option Explicit On Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class FileImporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileImporter") System.Threading.Thread.Sleep(500) RaiseEvent EventTwo("Event two from FileImporter", i) System.Threading.Thread.Sleep(500) Next i End Sub End Class Public Class FileExporter Implements IProxyProgress Implements IFileProcessor Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEvent EventOne("Event one from FileExporter") System.Threading.Thread.Sleep(interval) RaiseEvent EventTwo("Event two from FileExporter", i) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub Main() ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test MainAsync() End Sub Sub MainAsync() Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter() proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module -- Shamil _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Jan 3 09:33:14 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 03 Jan 2008 16:33:14 +0100 Subject: [dba-VB] inheriting events Message-ID: Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined-from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... From shamil at users.mns.ru Thu Jan 3 11:47:29 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 3 Jan 2008 20:47:29 +0300 Subject: [dba-VB] inheriting events In-Reply-To: Message-ID: <000001c84e30$b5949730$6501a8c0@nant> Hi Gustav, Please do not frame "these golden words" :) I mean it's of course better to have all these principles in one's active set of best programming practices... If you frame "these golden words" somebody may think I'm a kind of "preaching for ignorance", and I'm not I think.... Thanks. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 03, 2008 6:33 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 4 06:02:34 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 04 Jan 2008 13:02:34 +0100 Subject: [dba-VB] inheriting events Message-ID: Hi Shamil Rest assured, I do keep them in my head - in fact I think I've always worked this way without feeling ignorant. /gustav >>> shamil at users.mns.ru 03-01-2008 18:47 >>> Hi Gustav, Please do not frame "these golden words" :) I mean it's of course better to have all these principles in one's active set of best programming practices... If you frame "these golden words" somebody may think I'm a kind of "preaching for ignorance", and I'm not I think.... Thanks. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 03, 2008 6:33 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hi Shamil Thanks - I'll frame these golden words and nail them to the wall - so I can relax and not feel like an idiot when all the buzz words fly around my head when the big guys discuss why principle X is preferable for method Y (or is it vice versa?) /gustav >>> shamil at users.mns.ru 03-01-2008 16:05:39 >>> I must say when I program something these days I do know there are many principles used in this my programming but I often do not know how they are called - have a look at this list: http://rearchitect.wordpress.com/2006/02/12/software-design-principles-mined -from-books-and-papers/ I'd bet you use many of these principles being an experienced developer but if I ask you why you use them that would be not always easy to answer, correct? :) (I mean when I do program something the first principle I use is how good and streamlined the code I'm writing looks - if it doesn't and I have time I do continue refactoring it until I see there is nothing to cut out/refactor to make it even more simple and streamlined - and that always works well - it's a simple principle :) but it isn't easy to explain that simple principle(s) - they should be better shown as examples... From shamil at users.mns.ru Fri Jan 4 18:49:11 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 5 Jan 2008 03:49:11 +0300 Subject: [dba-VB] inheriting events In-Reply-To: <001401c84e18$14af6600$657aa8c0@M90> Message-ID: <000001c84f34$c9503630$6501a8c0@nant> Hello John, As promised yesterday - here is a solution with multi-threading based on article I mentioned in this thread already: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 1. Create WinForms sample app with Form1 form 2. Create two buttons Button1 and Button2 on this form 3. Create listbox ListBox1 4. Put this code behind for Form1 and set buttons' click event properly: Public Class Form1 : Implements IStatusDisplay Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() TestModule.MainSync(Me) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() TestModule.MainAsync(Me) End Sub Delegate Sub StringParameterDelegate(ByVal value As String) Public Sub UpdateStatus(ByVal value As String) _ Implements IStatusDisplay.UpdateStatus If (Me.InvokeRequired) Then Me.BeginInvoke(New StringParameterDelegate( _ AddressOf UpdateStatus), New Object() {value}) Return End If ListBox1.Items.Add(value) Application.DoEvents() End Sub End Class 5. put this code into Module1 Option Explicit On Public Interface IStatusDisplay Sub UpdateStatus(ByVal value As String) End Interface Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Protected _display As IStatusDisplay Public Sub New(ByVal display As IStatusDisplay) _display = display End Sub Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventOne(message) _display.UpdateStatus(message) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventTwo(message, count) _display.UpdateStatus(message + ", count=" + count.ToString()) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub MainSync(ByVal display As IStatusDisplay) ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test 'MainAsync() End Sub Sub MainAsync(ByVal display As IStatusDisplay) Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module Enjoy multi-threading! :) If you find bugs please post fixes here. Thanks. -- Shamil P.S. Notes: 1. Watch line wraps in the code above 2. I did leave Console.WriteLine(...) in the above code to see how yesterday's console app code was refactored into winforms code - as you can find that weren't many changes... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:51 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com From jwcolby at colbyconsulting.com Fri Jan 4 18:53:32 2008 From: jwcolby at colbyconsulting.com (jwcolby) Date: Fri, 4 Jan 2008 19:53:32 -0500 Subject: [dba-VB] inheriting events In-Reply-To: <000001c84f34$c9503630$6501a8c0@nant> References: <001401c84e18$14af6600$657aa8c0@M90> <000001c84f34$c9503630$6501a8c0@nant> Message-ID: <005901c84f35$651c65c0$657aa8c0@M90> Thanks Shamil. I'll absorb this and see how I can apply it to my code. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Friday, January 04, 2008 7:49 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Hello John, As promised yesterday - here is a solution with multi-threading based on article I mentioned in this thread already: http://www.yoda.arachsys.com/csharp/threads/winforms.shtml 1. Create WinForms sample app with Form1 form 2. Create two buttons Button1 and Button2 on this form 3. Create listbox ListBox1 4. Put this code behind for Form1 and set buttons' click event properly: Public Class Form1 : Implements IStatusDisplay Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.Clear() TestModule.MainSync(Me) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() TestModule.MainAsync(Me) End Sub Delegate Sub StringParameterDelegate(ByVal value As String) Public Sub UpdateStatus(ByVal value As String) _ Implements IStatusDisplay.UpdateStatus If (Me.InvokeRequired) Then Me.BeginInvoke(New StringParameterDelegate( _ AddressOf UpdateStatus), New Object() {value}) Return End If ListBox1.Items.Add(value) Application.DoEvents() End Sub End Class 5. put this code into Module1 Option Explicit On Public Interface IStatusDisplay Sub UpdateStatus(ByVal value As String) End Interface Public Interface IProxyProgress Event EventOne(ByVal msg As String) Event EventTwo(ByVal msg As String, ByVal count As Integer) End Interface Public Interface IFileProcessor Sub Execute(ByVal sleepInterval As Object) End Interface Public Class ProxyProgress Implements IProxyProgress Protected _display As IStatusDisplay Public Sub New(ByVal display As IStatusDisplay) _display = display End Sub Private Event EventOne(ByVal msg As String) _ Implements IProxyProgress.EventOne Private Event EventTwo(ByVal msg As String, ByVal count As Integer) _ Implements IProxyProgress.EventTwo Protected Sub RaiseEventOne(ByVal msg As String, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventOne(message) _display.UpdateStatus(message) End Sub Protected Sub RaiseEventTwo(ByVal msg As String, ByVal count As Integer, ByVal eventSource As Type) Dim message As String = eventSource.ToString() + ": " + msg RaiseEvent EventTwo(message, count) _display.UpdateStatus(message + ", count=" + count.ToString()) End Sub End Class Public Class FileImporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) _ Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(interval) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(interval) Next i End Sub End Class Public Class FileExporter Inherits ProxyProgress Implements IFileProcessor Public Sub New(ByVal display As IStatusDisplay) MyBase.New(display) End Sub Private Sub Execute(ByVal sleepInterval As Object) Implements IFileProcessor.Execute Dim interval As Integer = CType(sleepInterval, Integer) For i As Integer = 1 To 5 RaiseEventOne("Event one", Me.GetType()) System.Threading.Thread.Sleep(500) RaiseEventTwo("Event two", i, Me.GetType()) System.Threading.Thread.Sleep(500) Next i End Sub End Class Module TestModule Private Sub EventOneHandler(ByVal msg As String) Console.WriteLine("EventOneHandler: " + msg) End Sub Private Sub EventTwoHandler(ByVal msg As String, ByVal count As Integer) Console.WriteLine(String.Format("EventTwoHandler: {0}, count = {1}", msg, count)) End Sub Sub MainSync(ByVal display As IStatusDisplay) ' Sync Dim list As List(Of IFileProcessor) = _ New List(Of IFileProcessor) Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler list.Add(fileProcessor) For Each fileProcessor In list fileProcessor.Execute(300) Next fileProcessor ' async test 'MainAsync() End Sub Sub MainAsync(ByVal display As IStatusDisplay) Dim workers(2) As System.Threading.Thread Dim fileProcessor As IFileProcessor = Nothing Dim proxyProgress As IProxyProgress = Nothing ' one fileProcessor = New FileImporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(0) = New Threading.Thread(AddressOf fileProcessor.Execute) ' two fileProcessor = New FileExporter(display) proxyProgress = DirectCast(fileProcessor, IProxyProgress) AddHandler (proxyProgress.EventOne), AddressOf EventOneHandler AddHandler (proxyProgress.EventTwo), AddressOf EventTwoHandler workers(1) = New Threading.Thread(AddressOf fileProcessor.Execute) workers(0).Start(200) workers(1).Start(1000) End Sub End Module Enjoy multi-threading! :) If you find bugs please post fixes here. Thanks. -- Shamil P.S. Notes: 1. Watch line wraps in the code above 2. I did leave Console.WriteLine(...) in the above code to see how yesterday's console app code was refactored into winforms code - as you can find that weren't many changes... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby Sent: Thursday, January 03, 2008 5:51 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] inheriting events Shamil, This is in fact what I was doing (minus the interfaces). A straight base class with the events and methods that can be called to raise the methods. then the process classes inherit the base class and call the methods when they want to raise the events. John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Thu Jan 10 11:18:32 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 10 Jan 2008 18:18:32 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From cfoust at infostatsystems.com Thu Jan 10 14:31:29 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Thu, 10 Jan 2008 12:31:29 -0800 Subject: [dba-VB] Compiling Class Library In-Reply-To: References: Message-ID: I don't know if you CAN get rid of the message. You can't run a class library or any class directly, so the message is accurate. You're editing a class library referenced in the other solution/project you have open and trying to immediately reflect those changes. I stopped trying that after the first time. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 9:19 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From R.Griffiths at bury.gov.uk Fri Jan 11 03:06:56 2008 From: R.Griffiths at bury.gov.uk (Griffiths, Richard) Date: Fri, 11 Jan 2008 09:06:56 -0000 Subject: [dba-VB] Compiling Class Library In-Reply-To: References: Message-ID: <200801110850.m0B8oDO11368@smarthost.yourcomms.net> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com ----------------------------------------------------------------- Why not visit our website www.bury.gov.uk ----------------------------------------------------------------- The information contained in this e-mail and any files transmitted with it is for the intended recipient(s) alone. It may contain confidential information that is exempt from the disclosure under English law and may also be covered by legal,professional or other privilege. If you are not the intended recipient, you must not copy, distribute or take any action in reliance on it. If you have received this e-mail in error, please notify us immediately by using the reply facility on your e-mail system. If this message is being transmitted over the Internet, be aware that it may be intercepted by third parties. As a public body, the Council may be required to disclose this e-mail or any response to it under the Freedom of Information Act 2000 unless the information in it is covered by one of the exemptions in the Act. By responding to this e-mail you accept that your response may be subject of recording/monitoring to ensure compliance with the Council's ICT Security Policy. Electronic service accepted only at legalservices at bury.gov.uk and on fax number 0161 253 5119 . ************************************************************* From Gustav at cactus.dk Fri Jan 11 08:29:41 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 15:29:41 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Charlotte True, but I had to do some debugging which required minor changes to the library which, by the way, is not used by any other project. /gustav >>> cfoust at infostatsystems.com 10-01-2008 21:31:29 >>> I don't know if you CAN get rid of the message. You can't run a class library or any class directly, so the message is accurate. You're editing a class library referenced in the other solution/project you have open and trying to immediately reflect those changes. I stopped trying that after the first time. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 9:19 AM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From Gustav at cactus.dk Fri Jan 11 08:55:47 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 15:55:47 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Richard OK, that makes sense. But how? If I open Add Reference I have tabs: .NET, COM, Projects, Browse, Recent However, tab Projects is empty. Now, I can add the Class Library as a project, and that causes the main project to be wrapped in a Solution given the name of the main project. Then, if I open Add Reference for either project (main or library), the other project is listed as a reference. Is this what I should do? /gustav >>> R.Griffiths at bury.gov.uk 11-01-2008 10:06:56 >>> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From shamil at users.mns.ru Fri Jan 11 09:35:49 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Fri, 11 Jan 2008 18:35:49 +0300 Subject: [dba-VB] Compiling Class Library In-Reply-To: Message-ID: <000001c85467$a48910f0$6401a8c0@nant> Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 11 10:13:10 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 17:13:10 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Richard Small correction: Then, if I open Add Reference for either project (main or library), the other project is listed as a possible reference. /gustav >>> Gustav at cactus.dk 11-01-2008 15:55:47 >>> Hi Richard OK, that makes sense. But how? If I open Add Reference I have tabs: .NET, COM, Projects, Browse, Recent However, tab Projects is empty. Now, I can add the Class Library as a project, and that causes the main project to be wrapped in a Solution given the name of the main project. Then, if I open Add Reference for either project (main or library), the other project is listed as a reference. Is this what I should do? /gustav >>> R.Griffiths at bury.gov.uk 11-01-2008 10:06:56 >>> Hi If you add the reference of the class library as type 'project' then you don't need two VS2005 sessions and can edit the class library within the main app. Richard -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: 10 January 2008 17:19 To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From cfoust at infostatsystems.com Fri Jan 11 10:13:25 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Fri, 11 Jan 2008 08:13:25 -0800 Subject: [dba-VB] Compiling Class Library In-Reply-To: <000001c85467$a48910f0$6401a8c0@nant> References: <000001c85467$a48910f0$6401a8c0@nant> Message-ID: Yes, that's the way we build ours too. Our apps are solutions that contain multiple projects, some of which are shared with our other apps. Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Shamil Salakhetdinov Sent: Friday, January 11, 2008 7:36 AM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Compiling Class Library Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 11 10:29:03 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 11 Jan 2008 17:29:03 +0100 Subject: [dba-VB] Compiling Class Library Message-ID: Hi Shamil and Charlotte The scenario you and Charlotte describe seems to be the right way to do it when the classlibs are under your control. What I did originally was to reference the compiled dll, and I guess there really is no reason to do so unless you don't have the source available. Then, when referencing the dll of the classlib, (re)building the classlib doesn't seem to push the changes to the main project. I agree with Shamil that VS is great. The more you work with it the more you appreciate it and all its features and how well they are thought out ... /gustav >>> shamil at users.mns.ru 11-01-2008 16:35:49 >>> Hello Gustav, You can use CTRL+SHIFT+B to rebuild classlib. What kind of programming are you doing? Depending on that you can keep (all) your classlib projects, (FEs), which use them etc. in one solution: I e.g. have here one of the solutions with 15 projects: 10+ classlibs, console-apps/-utilities, "test-bed"/unit testing classlibs/console-apps, COM-exposed classlib to use from within VBA etc. All that 15 classlibs can be recompiled in several seconds... And I do have another rather large ASP.NET 2.0 web-site solution, which does use the first solution projects' classlibs... And all works so well in ensamble that I must "take-off my hat" and say to MS Software Design Engeenier (in Test) and PMs that they did develop fantastic software development platform... I haven't seen yet VS2008 - as William told us here it's even more fantastic... -- Shamil P.S. Well, VS 2005 with ASP.NET 2.0 large website projects and complicated webforms does GPF sometimes... Still it's a fantastic set of development tool applicable for every development area and task... -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 10, 2008 8:19 PM To: dba-VB at databaseadvisors.com Subject: [dba-VB] Compiling Class Library Hi all In VS2005 I have a project with a reference to Class Library. When I have both opened in two sessions of VS and editing both, I've found that I have to run Debug (F5) in the Class Library to have changes reflected at once in the main project. That's fine, but when I do so, the Class Library pops an error message that - of course - a "Class Library cannot be started directly". How can I get rid of this error message? Or am I doing this in an unauthorized way? /gustav From john at winhaven.net Wed Jan 23 13:58:52 2008 From: john at winhaven.net (John Bartow) Date: Wed, 23 Jan 2008 13:58:52 -0600 Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell Message-ID: <200801231958.m0NJwkZF002102@databaseadvisors.com> It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Bryan Carbonell with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com From john at winhaven.net Wed Jan 23 14:00:27 2008 From: john at winhaven.net (John Bartow) Date: Wed, 23 Jan 2008 14:00:27 -0600 Subject: [dba-VB] DBA Award Announcement - Jim Lawrence Message-ID: <200801232000.m0NK0Oin003206@databaseadvisors.com> It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Jim Lawrence with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. http://www.winhaven.net/misc/JimLawrence.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com From garykjos at gmail.com Wed Jan 23 14:59:50 2008 From: garykjos at gmail.com (Gary Kjos) Date: Wed, 23 Jan 2008 14:59:50 -0600 Subject: [dba-VB] [dba-OT] DBA Award Announcement - Bryan Carbonnell In-Reply-To: <200801231958.m0NJwkZF002102@databaseadvisors.com> References: <200801231958.m0NJwkZF002102@databaseadvisors.com> Message-ID: Yes, THANK YOU BRYAN! GK On 1/23/08, John Bartow wrote: > It is with great pleasure that the Board of Directors for Database Advisors, > Inc. presents Bryan Carbonell with a Special Service Award in deep > appreciation for all that he has done for Database Advisors as List Master. > We value his dedication, professionalism and the sharing of his talents and > we look forward to continuing our work together. > > Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm > > John Bartow, President > Database Advisors, Inc. > Email: mailto:president at databaseadvisors.com > Website: http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-OT mailing list > dba-OT at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-ot > Website: http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com From garykjos at gmail.com Wed Jan 23 15:00:34 2008 From: garykjos at gmail.com (Gary Kjos) Date: Wed, 23 Jan 2008 15:00:34 -0600 Subject: [dba-VB] [dba-OT] DBA Award Announcement - Jim Lawrence In-Reply-To: <200801232000.m0NK0Oin003206@databaseadvisors.com> References: <200801232000.m0NK0Oin003206@databaseadvisors.com> Message-ID: Yes, THANK YOU JIM! GK On 1/23/08, John Bartow wrote: > It is with great pleasure that the Board of Directors for Database Advisors, > Inc. presents Jim Lawrence with a Special Service Award in deep appreciation > for all that he has done for Database Advisors as List Master. We value his > dedication, professionalism and the sharing of his talents and we look > forward to continuing our work together. > > http://www.winhaven.net/misc/JimLawrence.htm > > John Bartow, President > Database Advisors, Inc. > Email: mailto:president at databaseadvisors.com > Website: http://www.databaseadvisors.com > > > > > _______________________________________________ > dba-OT mailing list > dba-OT at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-ot > Website: http://www.databaseadvisors.com > -- Gary Kjos garykjos at gmail.com From cfoust at infostatsystems.com Wed Jan 23 15:16:58 2008 From: cfoust at infostatsystems.com (Charlotte Foust) Date: Wed, 23 Jan 2008 13:16:58 -0800 Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell In-Reply-To: <200801231958.m0NJwkZF002102@databaseadvisors.com> References: <200801231958.m0NJwkZF002102@databaseadvisors.com> Message-ID: Congratulations, Bryan. No wonder I didn't see this in AccessD!! LOL Charlotte Foust -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of John Bartow Sent: Wednesday, January 23, 2008 11:59 AM To: dba-sqlserver at databaseadvisors.com; _DBA-Access; dba-ot at databaseadvisors.com; _DBA-Owners; _DBA-Tech; dba-vb at databaseadvisors.com Subject: [dba-VB] DBA Award Announcement - Bryan Carbonnell It is with great pleasure that the Board of Directors for Database Advisors, Inc. presents Bryan Carbonell with a Special Service Award in deep appreciation for all that he has done for Database Advisors as List Master. We value his dedication, professionalism and the sharing of his talents and we look forward to continuing our work together. Award link: http://www.winhaven.net/misc/BryanCarbonnell.htm John Bartow, President Database Advisors, Inc. Email: mailto:president at databaseadvisors.com Website: http://www.databaseadvisors.com _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 25 05:02:16 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 12:02:16 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of-dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Fri Jan 25 10:23:10 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Fri, 25 Jan 2008 19:23:10 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <001801c85f6e$93a90cb0$6501a8c0@nant> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Fri Jan 25 13:16:09 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:16:09 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil True, and the benchmarks in article shows this too. But for this case with only about 5000 records speed is not important and then I learn something new. It took me a while to find out that you have to use this syntax to create the procedure: CREATE PROCEDURE Something AS EXTERNAL NAME assembly.[namespace.class].method This is for SQL Server 2005 and .Net 2.0. Don't know if it has improved in SQL Server 2008. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From Gustav at cactus.dk Fri Jan 25 13:37:45 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:37:45 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From Gustav at cactus.dk Fri Jan 25 13:54:24 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Fri, 25 Jan 2008 20:54:24 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Located this on the issue: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=95554 /gustav >>> Gustav at cactus.dk 25-01-2008 20:37:45 >>> Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Fri Jan 25 15:09:30 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Sat, 26 Jan 2008 00:09:30 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <000601c85f96$93d28680$6501a8c0@nant> Hello Gustav, CLR stored procedures can have output parameters (but not return values) of many different types... There are also CLR Scalar-Valued Functions (SVFs), which return a single value. SVFs can return any scalar type, excluding varchar, char, rowversion, text, ntext, image, timestamp, table, or cursor. This information is from the book: "Professional SQL ServerT 2005 CLR Programming with Stored Procedures, Functions, Triggers, Aggregates, and Types" By Derek Comingore and Douglas Hinson which is very good and covers all(?) the aspects on developing and deploying managed SPs, SVFs, triggers, ... for MS SQL 2005... I haven't yet used SQL 2005 CLR programming - I'm waiting for a customer to request for such programming :) - as far as I see from the book I mentioned above there is no any "black magic" there... BTW, this book has very detailed chapter (Chapter 5) comparing CLR and T-SQL performance - I'd dare to give here an short summary of this chapter: << As it relates to a performance comparison between SQL CLR and T-SQL, we have shown in this chapter that: - String parsing and processing perform better with less CPU resources using CLR base classes. - Computation of even simple proportions performs better in SQL CLR. - SQL CLR table-valued functions can stream results faster to client than T-SQL - T-SQL is still the king of data manipulation, extraction, and updating. >> I haven't seen yet/tried MS SQL 2008 - I will probably do that end of this year if not later... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 10:38 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From Gustav at cactus.dk Sun Jan 27 16:19:23 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Sun, 27 Jan 2008 23:19:23 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil Thanks. Looks like a very good reference. /gustav >>> shamil at users.mns.ru 25-01-2008 22:09 >>> Hello Gustav, CLR stored procedures can have output parameters (but not return values) of many different types... There are also CLR Scalar-Valued Functions (SVFs), which return a single value. SVFs can return any scalar type, excluding varchar, char, rowversion, text, ntext, image, timestamp, table, or cursor. This information is from the book: "Professional SQL ServerT 2005 CLR Programming with Stored Procedures, Functions, Triggers, Aggregates, and Types" By Derek Comingore and Douglas Hinson which is very good and covers all(?) the aspects on developing and deploying managed SPs, SVFs, triggers, ... for MS SQL 2005... I haven't yet used SQL 2005 CLR programming - I'm waiting for a customer to request for such programming :) - as far as I see from the book I mentioned above there is no any "black magic" there... BTW, this book has very detailed chapter (Chapter 5) comparing CLR and T-SQL performance - I'd dare to give here an short summary of this chapter: << As it relates to a performance comparison between SQL CLR and T-SQL, we have shown in this chapter that: - String parsing and processing perform better with less CPU resources using CLR base classes. - Computation of even simple proportions performs better in SQL CLR. - SQL CLR table-valued functions can stream results faster to client than T-SQL - T-SQL is still the king of data manipulation, extraction, and updating. >> I haven't seen yet/tried MS SQL 2008 - I will probably do that end of this year if not later... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 10:38 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil Oh, and some severe limitations too. This method returns an SqlBoolean: CREATE PROCEDURE failed because a CLR Procedure may only be defined on CLR methods that return either SqlInt32, System.Int32, void. So ... /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From djkr at msn.com Sun Jan 27 18:36:37 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:36:37 -0000 Subject: [dba-VB] Performance in disc partitions In-Reply-To: Message-ID: I am about to partition a new disc. One partition will be very active in terms of reads and writes, another almost dormant. Is there any advantage in performance terms in having the active partition as the 'first' one on the disc? Or the last one? It's a long time since I was involved in disc layout at a low level, and I'm wondering whether 'cylinders' these days are still all the same size, with the data near the edge of the platter just more spread out than that near the spindle - or not? TIA John From djkr at msn.com Sun Jan 27 18:46:46 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:46:46 -0000 Subject: [dba-VB] Performance in disc partitions In-Reply-To: Message-ID: Aargh - sorry! I misposted this. It should have been to dba-Tech, where it now is. John -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of DJK(John) Robinson Sent: 28 January 2008 00:37 To: 'Discussion concerning Visual Basic and related programming issues.' Subject: [dba-VB] Performance in disc partitions I am about to partition a new disc. One partition will be very active in terms of reads and writes, another almost dormant. Is there any advantage in performance terms in having the active partition as the 'first' one on the disc? Or the last one? It's a long time since I was involved in disc layout at a low level, and I'm wondering whether 'cylinders' these days are still all the same size, with the data near the edge of the platter just more spread out than that near the spindle - or not? TIA John _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com From djkr at msn.com Sun Jan 27 18:49:29 2008 From: djkr at msn.com (DJK(John) Robinson) Date: Mon, 28 Jan 2008 00:49:29 -0000 Subject: [dba-VB] Recall: Performance in disc partitions Message-ID: The sender would like to recall the message, "Performance in disc partitions". From Gustav at cactus.dk Thu Jan 31 05:25:08 2008 From: Gustav at cactus.dk (Gustav Brock) Date: Thu, 31 Jan 2008 12:25:08 +0100 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Message-ID: Hi Shamil et al Here is what I did. Some of the data (from some "foreign" apps) are stored in mdb files. These I link to the SQL Server as "linked servers" to be able to import the data to the SQL Server on a regular basis. This is done via some simple queries (no joins, no aggregating) with some basic manipulation writing to similar tables in the server. These queries I can control from Visual Studio. However, VS will not connect directly to a linked server, only to normal databases of the SQL Server. So you will have to connect to such a database and then reference the linked server in a query. One advantage is, that the SQL syntax of such a query is that of SQL Server, not Access/JET. It took some research to locate the syntax for referencing a linked mdb - note the last line in the example here: Select varenr as ItemId, dessnr as DessinNo, case when ( case when isnumeric(right(dessnr, charindex('-', reverse(dessnr)))) <> 0 then convert(bigint, right(dessnr, charindex('-', reverse(dessnr)) - 1)) else 0 end) between 1 and 99 and charindex('-', dessnr) > 0 then rtrim(left( dessnr, len(dessnr) - charindex('-', reverse(dessnr)))) else dessnr end as DessinId >From linkeddb...tblDessin The advantage is, that all that is needed to be set up at the server is the links to the mdb files - the queries are controlled and maintained from VS, and the client apps do not need to know anything about the physical location of the mdb files, neither do they need to establish connections to these. >From this point I can easily store the data in server tables while recording some log details of success or failure. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav From shamil at users.mns.ru Thu Jan 31 07:27:19 2008 From: shamil at users.mns.ru (Shamil Salakhetdinov) Date: Thu, 31 Jan 2008 16:27:19 +0300 Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 In-Reply-To: Message-ID: <002101c8640d$01ae6d20$6501a8c0@nant> Hi Gustav, Yes, I did read about "linked servers", which could be any OLE DB (and ODBC?) data source AFAIK but I have never used them. Please post here some notes later when you get good experience of using them in your test/deployment environments... Thank you. -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Thursday, January 31, 2008 2:25 PM To: dba-vb at databaseadvisors.com Subject: Re: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi Shamil et al Here is what I did. Some of the data (from some "foreign" apps) are stored in mdb files. These I link to the SQL Server as "linked servers" to be able to import the data to the SQL Server on a regular basis. This is done via some simple queries (no joins, no aggregating) with some basic manipulation writing to similar tables in the server. These queries I can control from Visual Studio. However, VS will not connect directly to a linked server, only to normal databases of the SQL Server. So you will have to connect to such a database and then reference the linked server in a query. One advantage is, that the SQL syntax of such a query is that of SQL Server, not Access/JET. It took some research to locate the syntax for referencing a linked mdb - note the last line in the example here: Select varenr as ItemId, dessnr as DessinNo, case when ( case when isnumeric(right(dessnr, charindex('-', reverse(dessnr)))) <> 0 then convert(bigint, right(dessnr, charindex('-', reverse(dessnr)) - 1)) else 0 end) between 1 and 99 and charindex('-', dessnr) > 0 then rtrim(left( dessnr, len(dessnr) - charindex('-', reverse(dessnr)))) else dessnr end as DessinId >From linkeddb...tblDessin The advantage is, that all that is needed to be set up at the server is the links to the mdb files - the queries are controlled and maintained from VS, and the client apps do not need to know anything about the physical location of the mdb files, neither do they need to establish connections to these. >From this point I can easily store the data in server tables while recording some log details of success or failure. /gustav >>> shamil at users.mns.ru 25-01-2008 17:23:10 >>> Hello Gustav, I'd use T-SQL CASE and built-in T-SQL functions: REVERSE and CHARINDEX and SUBSTRING and/or I'd write UDFs using the listed above and other string functions, which are many in T-SQL... ...I'd use .NET code for something more like business functionality or when advanced parsing is needed etc. ... Just my opinion... -- Shamil -----Original Message----- From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Friday, January 25, 2008 2:02 PM To: dba-sqlserver at databaseadvisors.com; dba-vb at databaseadvisors.com Subject: [dba-VB] Performance of .Net Code in SQL Server 2005 Hi all I came across this interesting article: http://www.novicksoftware.com/coding-in-sql/Vol3/cis-v3-N14-performannce-of- dot-net-code-sql-server-2005.htm But is anyone here running .Net code in SQL Server? A client has an mdb file with poorly designed tables and sloppy data. The task is to clean these and transfer them to SQL Server tables with a better structure. I'm not so familiar in T-SQL, so I created queries in Access to test and view the possible output. A typical query contains code like this: SELECT .. IIf(InStrRev([dessNr],"-")>0 And IsNumeric(Right([dessNr],1)),Left([dessNr],InStrRev([dessNr],"-")-1),[dessNr ]) AS dessinNoBase T-SQL knows nothing about InStrRev so I looked for options on how to translate such functions. One option is to use .Net code. Speed is not important (small tables). How do I approach this? Well, the top links at that page link to presentations on: SQLCLR Programming with SQL Server 2005 Still, has anyone been working with this? /gustav _______________________________________________ dba-VB mailing list dba-VB at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-vb http://www.databaseadvisors.com