|
He's definitely been helping lots of people and doing a fine job at it.
I try to answer a question here or there when it's something I know off the top of my head and I happen to be looking, but he seems to be more like a lifeguard watching the water .
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
|
Nah, not an AI. Just a smart guy with a decent neural jack plugged in to MSDN and CodeProject!
Way to go, Heath. I rest well at night knowing that you're protecting the good programmers of Gotham City. You're all business.
Regards,
Jeff Varszegi
|
|
|
|
|
he makes fun of me alot...
cause i'm dumb.
/\ |_ E X E GG
|
|
|
|
|
Jeremy Kimball wrote:
I'm firmly convinced he's really an AI plugged into both the MSDN library and CodeProject.
I work with Heath daily and I can confirm he really is an AI bot. Just kidding, however he is definately a great resource, we just have to keep him in check with his M.I.S. jokes every once and a while.
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
Hi all,
I have 3 controls developed which are interdependent in a non cyclic way. when i use these controls and add them on my test windows form i am getting an error as
(JIT debugging failed with the following error : class not registered.
Please check the documentation for "Just In Time debugging errors" for more information)
I am not able to figure out wat the cause may be for this.
Can someone help me out with it.
Thanks
Rekha
|
|
|
|
|
If these are .NET controls, make sure you add a project reference, so that when you switch between debug, release, or any other build configurations the appropriate assemblies are referenced.
If these are COM controls for which you're creating an RCW, make sure the COM class or typelib is actually registered. Find the DLL or OCX and run regsvr32.exe filename.extension .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I need to create an audit form that runs on windows startup and requires the user to enter some details.
This exe needs to be modal to windows so that the user cannot do anything else until they have submitted the form at which point normal windows behaviour will return.
If anyone know how to do this then please let m know!
Thanks.
|
|
|
|
|
Create a new Windows Forms project, set the main form's TopLevel property to true (makes it a system modal dialog). When you install it, write it to the registry key in either HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE at Software\Microsoft\Windows\CurrentVersion\Run, or to the Startup folder in Start Menu\Programs\Startup for either the current user or "All Users".
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi all.
I have a implemented a Window Service which includes a timer. The timer
"ticks" every five minutes, and writes an entry to a database plus
enters a line into an eventlog.
Unfortunatelly this timer does not seem fully reliable as the service
occasionally just stop writing to both the database and the eventlog.
Sometimes this happens when it has been running for just a few hours,
other times when it has been going for several days. Is there a known
limitation in timers? Or is there some internal or external event that
might cause the timer to stop?
Since the timer does not 'die' at the same tick each time it is very
hard to try to debug or something. The code snippets below is pretty straight
forward, I hope you can follow it and that it may give you some clue as
to what is going wrong here.
Do you think it would help to implement a second timer that executes say every
ten hours, which creates a new instance of the first timer? That of
course would leave me at the mercy of the second timer and in the case
where an external event causes the first timer to stop it will most
certainly also cause the second timer to stop...
Thanks
/EnkelIk
public class MyService : System.ServiceProcess.ServiceBase
{
private Timer vscTimer=null;
public MyService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
//Create eventlog
if(!System.Diagnostics.EventLog.SourceExists("MyServiceLogSource"))
System.Diagnostics.EventLog.CreateEventSource("MyServiceLogSource","MyServiceLog");
eventLog.Source = "MyServiceLogSource";
eventLog.Log="MyServiceLog";
double interval=300000;
vscTimer = new Timer(interval);
vscTimer.Elapsed += new ElapsedEventHandler( this.ServiceTimer_Tick );
}
...
[ Auto generated code for initializing and disposing
process ]
...
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
//Start timer
vscTimer.AutoReset=true;
vscTimer.Enabled=true;
vscTimer.Start();
}
private void ServiceTimer_Tick(object sender, System.Timers.ElapsedEventArgs e)
{
this.vscTimer.Stop();
eventLog.WriteEntry("Timer event!");
[Write to database]
//Tried to do something about the huge memory consumption...
GC.Collect();
//Restart timer
this.vscTimer.Start();
}
}
|
|
|
|
|
Dear EnkelIk,
i have the same broblem with dieing the timers so you should use the timer of threading try
System.Threading.Timer
this class is beter that the standered one you can create it by using call back function it is good one so try it
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
Thanks.
Using System.Threading.Timer plus improved error handling (try-catch) my service seems much more stable than before.
Again, THANKS!
/EnkelIk
|
|
|
|
|
Several things: if you read the documentation for Start and Stop , they are exactly the same as passing true and false to the Timer.Enabled property, respectively. Don't do both because it's a waste of CPU time.
Second, it is recommended that you don't use GC.Collect . Instead, dispose of the objects in your "[Write to database]" block that implement IDisposable .
Finally: exception handling and stopping / starting timers. What's probably happening is that since you're stopping the timer, writing to the event log, and then performing database functions - which can be volatile - and then starting the timer again, if an exception were to be thrown your time would not be started again! Instead, put your database calls in a try-catch and gracefully catch all exceptions, or add this.vscTimer.Start() to a finally block of a try-catch-finally or try-finally (exceptions are still thrown in the latter block, but finally is always executed regardless of success.
You should also enable auto-logging on the Windows Service by setting ServiceBase.AutoLog to true (of course, your service inherits ServiceBase , so you can set this property on yourself, too).
One more option: don't stop the timer! If you don't stop it, even if the database code throws an exception, the timer will keep running. Besides, lets say all the database code takes 2 seconds and you run this code every 10 minutes. That means that you're shifting time about 4.8 minutes per day! Just let it run, man!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath,
I haven't seen the code that causes this problme so I may not be making any sense here. Feel free to use your vast reserves of knowledge to correct me.
The .NET timer class uses the .NET built-in thread pool to execute the timer callback function. The .NET built-in thread pool has a maximum of 25 threads as the default limit. If the timer callback function got stuck (with some database operations, for example) for longer than the timer interval (5 minutes in this case), the timer callback function will be invoked by a new thread from the thread pool. If this new thread got stuck again, then another new thread from the thread pool will be used.
Anyway, under some conditions, the timer can exaust all 25 threads from the thread pool. I have posted a simple example in a message after my article Creating Your Own Thread Pool In .NET[^] to demonstrate this.
If there is no easy way to figure out what caused the timer callback to stuck, then the solution may be not using the .NET timer class at all or restarting the applcation when too many threads are being used to handle the timer event.
My articles and software tools
|
|
|
|
|
Thanks, but I don't think that was his problem. His Elapsed handler stopped the timer, ran some database code, then started the timer again after the database code completed. The database code was not wrapped in a try-catch block and if any exceptions where thrown, the timer would not be restarted.
Or am I missing your point?
BTW, I've read your article and found it very interesting. Good job!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
Thanks, but I don't think that was his problem.
You are right again. I wasn't reading the code in his post carefully. Thanks.
My articles and software tools
|
|
|
|
|
Thanks.
Using System.Threading.Timer plus improved error handling (try-catch) my service seems much more stable than before. It's quite true that I have no need to stop and start the timer (even when not using the Threading timer), don't know why I got that idea.
I have also with interest read Xiangyang Liu's article but I don't think that will be any serious and frequent problem in my case.
Again, THANKS!
/EnkelIk
|
|
|
|
|
Hi Friends,
when i call a MSMAPI object from a standalone exe in VB .NET, i am able to send a mail. But when i spawn this exe as a process from a windows service, i get an error message while signing on using the MAPI session SignOn() method. I tried using windows service logon as both local system and using my NT logon too. The error message thrown is
System.Runtime.InteropServices.COMException (0x800A7D1A): Not supported
at MSMAPI.MAPISessionClass.SignOn()
at ProcTryMail.tryMail.Pr_SendMail() in D:\Projects\Ems\Backup_Nov17OutSeq\ProcTryMail\tryMail.vb:line 20
My feeling was that some security access is required.
The code i have used is:
Public Class tryMail
Private objMapiSession As MSMAPI.MAPISession
Private objMapiMsgs As MSMAPI.MAPIMessages
Private i As Boolean
Public Sub Pr_SendMail()
Try
objMapiSession = New MSMAPI.MAPISession()
objMapiMsgs = New MSMAPI.MAPIMessages()
objMapiSession.SignOn()
objMapiMsgs.SessionID = objMapiSession.SessionID
objMapiMsgs.Compose()
objMapiMsgs.RecipDisplayName = "--give some mail id here--"
objMapiMsgs.MsgSubject = "From .NET MAPI"
objMapiMsgs.Send()
objMapiSession.SignOff()
Catch
End Try
End Sub
End class
Will be grateful if anyone of u is able to find out the problem.
Thanks
Alex
|
|
|
|
|
Ack, VB.NET! You did notice this was the C# forum, right? Fortunately for you, VB.NET, C#, and all other language that target the CLR use the same BCL and all assemblies the same way, too (since they're all compiled down to IL)...and some actually understand / remember that!
There doesn't appear to be anything wrong with your code (other than the obvious - it's VB.NET ). I don't know anything about MSMAPI (is this a Microsoft wrapper assembly, or something else you found online), but I do know that with functions like MAPILogon you either have to provide a profile name or specify the MAPI_LOGON_UI flag to have the function prompt the user for a profile to pick. I see nothing about you setting up a profile. This is predicated on different assumptions, though, like that this hasn't already been done under the covers for you already.
About the only thing I can tell you is to read the documentation for MSMAPI and take a look at some of the relevant MAPI functions and interfaces, like MAPILogon . Perhaps more information about that error code will be provided (of course, you may have to search the C/C++ header files for the preproc definition to which that error code is defined).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath, problem here is of accessing my local mail client from a windows service. Guess that would remain the same for any language at all. This code works for me as a stand alone exe. It takes the default profile and password of my client (microsoft outlook). MSMAPI is Microsoft Mail API underlying outlook.
Problem comes when this exe is spawned from a windows service as a separate process. Its on the SignOn() method, that it says method not supported.
|
|
|
|
|
I know what MAPI is, I'm just wondering where you got this component. Is it just a RCW (COM interop assembly)?
In any case, is the "Interact with Desktop" option enabled for the service. Since it executes your MAPI client (Outlook in your case), it must be able to interact with the desktop.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Your service is probably using the default "Local System" account, which does not have access to your e-mail profile. What you have to do is reconfigure your service to run under your own account, or the account that owns the e-mail profile:
1. Open the "adminstrative tools" menu, click the services submenu to open a window displaying the list of all services.
2. Double click your service in the list and then click the "Logon" tab.
3. Enter the correct user name and password, click "OK" to close the window.
4. Restart your service.
My articles and software tools
|
|
|
|
|
Not sure where to post this. Is there a builtin function or easy way to convert upper-unicode characters to their escaped HTML equivalent? I.E. I have a string defined and written out to HTML as:
string testString = "[\u2026]";
writer.Write(testString);
What I would like in the resulting HTML output is "[&#8230;]", but what I get is the actual unicode byte. I have tried HtmlEncode and various Text.Encoding but they do not handle this... Is there any builtin functions to handle this, or is a funciton needed to loop through the bytes in the string and escape the characters?
FYI: This is just a simple test, the actual data is from an outside data-source and has these characters in it which I need to escape.
|
|
|
|
|
See the HttpUtility.HtmlEncode method. It's static and can be used outside the scope of ASP.NET.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Actually that was the first thing I tried and it doesn't work:
string testString = "[\u2026]";
HttpUtility.HtmlEncode(testString, writer);
doesn't encode it to be … - it just leaves it as the unicode character (which displays as garbage). It seems like it should work, or there should be a builtin function to do this...
|
|
|
|