|
Dear Steve
Thank you very much!!! I tried with ' around before, but i completely
forgot about # signs.
It works like magic now.
Thank you
Ilya P.
|
|
|
|
|
iluha wrote:
Thank you very much!!! I tried with ' around before, but i completely
forgot about # signs.
Access uses the # sign where SQL Server uses a single quote.
-Nick Parker
|
|
|
|
|
I'm building a Service in VB.NET: It's basically watching for a file to appear in a directory; when it does, it processes that file into a database. Depending on the size of the data file, this process can take some time.
What I want to be able to do is prevent the Service Control Manager (SCM) from shutting my service down while it's busy. What is the best way to do this? I tried setting Me.CanStop to false on the fly, but found that it can't be changed while the service is running.
The one idea I've had so far is to create a boolean called isBusy that is set to true while processing and false while idle. Then, in the OnStop event do the following to prevent the stop until the task is done:
Do While isBusy
DoEvents
Loop
But, then what happens when this exceeds the timeout that the SCM has? The SCM reports an error, but does the service eventually shutdown? My main concern is finding a way for my user to shut the service down without shutting down in the middle of a task.
Thanks for any insight.
|
|
|
|
|
I don't think that you can prevent the service form being shutdown.
If all you are trying to do is preserve the integrity of the data that you are importing you can look into other ways to do this, perhaps locally creating the record set then adding it to the DB (this might be faster then adding it to the DB as you read from the file), or try adding the data to the DB inside of a transaction. That way it can be aborted if someone decides to stop in the middle and you won't get partial processed data.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
Once the SCM signals the service to shutdown, it will, event if the SCM doesn't "see" it happen. I recommend you don't use a simple boolean, however. Look at the System.Threading namespace, specifically Mutexes or Monitors. These are much safer to use. Basically, the file parsing / processing procedure and the code snippet you wrote above share a mutex or semaphore (a WaitHandle in most cases in .NET) You would obtain an exclusive lock on the mutex / semaphore before doing all your processing. If close is called it'll wait till it can receive an exclusive lock. The reverse is also true, but that processing proc won't be called when the service is shutdown obviously. Basically, however gets an exclusive lock on the mutex first wins and the other(s) wait until they can get an exclusive lock before running their code. This is far more safe.
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|
Thanks for the advice. Let me see if I understand the basic concept:
At the beginning of the processing section that I want to be "uninterruptible":
Try<br />
Dim M As New Threading.Mutex(True, "myUniqueCode")<br />
' do the processing<br />
Finally<br />
M.Close()<br />
End Try
In the OnStop event
Dim M As New Threading.Mutex(True, "myUniqueCode")<br />
Do Until M.WaitOne(1000, False)<br />
Loop<br />
M.Close()<br />
'do any resource cleanup here
Related question: What is the correct way to shut down my service from within it's own code? For example, if my service encounters a condition that tells it to end (other than the SCM's stop command), how does it shut itself down cleanly? I read somewhere that the END command is considered bad form for services.
Long term, my application will consist of multiple services (each with their own uninterruptable sections). Some will be more sensitive to this issue than others. I'm thinking of creating an applet that will send a message to each of them and they will shut themselves down when they are free from whatever they were doing). The applet can show the status of each one in turn so the user can watch them shutting down and know when it is safe to proceed.
|
|
|
|
|
Actually, this probably wouldn't work. Since you're requesting initial ownership in the same thread, the call to WaitOne() (or its equivalent in the constructor that requests initial ownership) will pass. Read the docs on Mutexes and you'll see that a thread can request access to a Mutex multiple times without blocking. I'm not sure how you're threading your file processing procedure (which is a good idea to do, btw), but doing them in the same thread would not work. Instead, take a look at the SyncRoot keyword in Visual Basic. Basically, declare a shared variable somewhere in your class:
Private Shared syncRoot As Object = New Object()
Then, in both methods, you can do the following (although there's no timeout, but these keywords boil down to a Monitor at compile time, so take a look at that for more details):
SyncLock (syncRoot)
' Do work
End SyncLock
Hope this helps.
Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN
|
|
|
|
|
Hi,
I would suggest a different approach. Let the service start a separate program with the file name as a parameter. Let that program deal with the database as long as it needs to.
By doing this your service can do its new function regardless of the the file size.
Of course I am assuming that a service can launch an application - I may be wrong.
Regards
Ekareem.
|
|
|
|
|
I am just wondering if anyone else has had this problem. I made a little app, that i put a web browser control on it, and navigated to a page, say www.thecodeproject.com. If I then set the ShowInTaskbar property in code somewhere, the web browser control disappears and i cannot get it to come back. I have tried like browser.show, browser.visible = true, etc. Any suggestions or has anyone else had this problem?
|
|
|
|
|
How can i print the contents of the listview control(including header) to printer using VB.NET,
can anybody please help me with code
Thank U
|
|
|
|
|
I am looking for al line-control for VB. (maybe VB.NET - But I still haven't switched to)
Ideally it would work like the "connections" between shapes in Excel.
The line should present a connection between some self-made controls. The user should be able to edit the lines, so that he/she can make a little network (1 to 2 screens full).
Up to now I've done some experiments with the existing line:
Determing the distance between the click(x/y) and a line => self-made "click" event ...
Thanks in advance.
Friedrich
|
|
|
|
|
Hi Everybody,
I need your help regarding Subclassing in VB.NET. I am developing a project in which I am using Web Browser Control as Winodws Explorer. Means I am providing most of the functionalities of Windows Explorer in my Web Browser control through my application.
I would like to SubClass the Web Browser Control and want to get the DELETE notification when user clicks on a button provided by interface. Or when user Right Click and chooses the "Delete" option from popup menu provided by Windows. Or, in Windows XP, user clicks the left panel entry "Delete this file" option.
I try to Subclass the Web Browser Control and try to get the DELETE notification. But application is not stable and also I am not able to trap the notification. While debuging or EXE of the application crashes as soon as I try to enter the mouse in the Web Browser Control.
Please, could you help me in this context?
I shall be very thankful to you for the same. Waiting for you early reply.
Best regards,
Vilas Shewale
|
|
|
|
|
Subclassing in VB Classic is notoriously unforgiving. One time I had a program with a subclass that brought down the whole computer whenever it was run.
I've had a lot of experience with subclassing in both VB Classic and C# so I might be able to help you.
Could you post your code? I might be able to spot a bug in it for you.
By the way, subclassing is much more stable when using an already-compiled dll like the SubClassing and Timer Assistant available at vbAccelerator[^].
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Hi,
Thank for your most earliest reply i ever had. I shall post the code to your email account. Please do the needful.
And i offer my deepest condolence for the crash of the machine.
Best regards,
Vilas Shewale
|
|
|
|
|
Hi,
Did you get anything regarding my problem? I'm waiting for your reply.
Best regards,
Vilas Shewale
|
|
|
|
|
villly wrote:
Did you get anything regarding my problem? I'm waiting for your reply.
Strange - I sent an email to you both direct and through CP the same night you posted here first. CP had an error, but the direct email wasn't returned, so I thought I had gotten through. Anyway, here it is.
**********EMAIL***************
Your problem probably has to do with the fact that the listview control that shows the files/folders is the one getting the delete message rather than the WebBrowser window which is its parent.
Fix: Get the child window's handle and the enumerate the windows to find a window with the classname "SHELLDLL_DefView". If this window doesn't recieve the delete messages, enumerate its child windows to find a window with the classname "SysListView32" and subclass it. Hefty fix, huh?
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Hi,
Thank you very much for your help. It's working properly. I subclass "SysListView32" object of Web Browser Control and getting the messages from it throught VB.NET's "System.Windows.Forms.NativeWindow".
Thank you very much for your help.
Best regards,
Vilas Shewale
|
|
|
|
|
Hi,
I am facing the same problem again but in different way now. I subclass "SysListView32" object to get the messages. It's working for other messages like mouse move, mouse over, etc. But I am not able to trap DELETE notofication in the same object.
MSDN help says the WM_DELETEITEM message is sent to the owner of a list box or combo box when the list box or combo box is destroyed or when items are removed by the LB_DELETESTRING, LB_RESETCONTENT, CB_DELETESTRING, or CB_RESETCONTENT message. So I try to trap the same message in my code. I am not able to get the DELETE notification by "SysListView32" object.
Could you help me in the same context? I want a message which will trap the DELETE message as soon as user will click on "Right click\Delete" or "Delete this file" from the left panel of Web Browser control.
Thank you very much for your help. I look forward to hear from you very soon.
Best regards,
Vilas Shewale
|
|
|
|
|
A listbox and a listview are to different things. List view notifications start with LVN_ rather than LB_.
BTW, you might want to try using the folder view's object model to intercept delete messages rather than trying to subclass the control.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Hi,
I didn't get the thing what you are trying to explain to me. Could you please send me some sample how i shall achieve the same? I shall wait for your sample code.
Thank in advance.
Best regards,
Vilas Shewale
|
|
|
|
|
villly wrote:
Could you please send me some sample how i shall achieve the same?
Soon I might be able to do this, but for now, look at the code in the file "folder.htt" in your Windows directory. This code deals with selecting, deleting, etc, of files/folders in the list view in explorer and the folder view.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Hi
What are the limitations of Visual Basic as compare to Microsoft Foundation Classes(MFC)?
e.g.
What we can't do in Visual Basic but it can be done using MFC.
Thanks
|
|
|
|
|
Just curious, but why aren't you asking this in the C++ Forum? Don't you think you'd get better answers there?
Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning
Mark Twain
Get your facts first, and then you can distort them as much as you please
Mark Twain
|
|
|
|
|
You're also not asking a question that has a direct answer. MFC is a bunch of classes/wrappers that make Win32 programming easier for C++. VB has access to about 90% of the Win32 API.
What are you thinking of doing?
RageInTheMachine9532
|
|
|
|
|
Why only 90%? In my humble experience, there are no WIN32API calls that cannot be made throuhg VB - at the end of the day, the WIN32 API itself is just a collection of C dlls - admittedly, it is necessary to funk about with custom types etc from time to time, but there you go - if you use a screwdriver to hammer a nail, you expect it to be difficult!
Totally open to correction on this one BTW....
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|