|
That's what I just got done saying: there are only two ways to invoke a script. Since the document isn't loaded, you can invoke an in-line script that is only executed while loading along with the rest of the document (which is why it works if you simply load the document with the script already in it). The only other way is through an event. Please read my first answer again. Your answer is there. We do a similar thing at work and it works fine.
-----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-----
|
|
|
|
|
Re: Reflection question
leppie 12:51 17 Nov '03
> I would think so, although i havent really looked at it explicitly. Generally there will still be a similar overhead as with delegates which is genrally 8 - 10 times slower than a normal non-virtual call. For maximum speed I recommend using an interface.
Dear Leppie, Sorry to post it late, I had to re-post this piece of our thread to remind you of the topic.
Can you please tell me what you mean by 'interface' here? is it related to run-time type access ??
Thank you
---
limit nSun = God
n → ∞
|
|
|
|
|
Basically:
You define a small assembly with some interfaces
eg.
public interface IFoo
{
int Bar();
string Name {get;}
}
Now in the loading assembly , you implement these interfaces, say class ABC : IFoo .
In the loader assembly, you use reflection to find the types in the loading assembly that implements IFoo , which in this case will be ABC . But we dont care what ABC does, only IFoo . So the ABC gets instantiated as an IFoo instance. Now withing your loader assembly, you simply call the interface.
It is a bit more work though, but it will be faster.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
This is just a large "attaboy" to Heath. It seems like every time I'm about to attempt an answer at a question here in the C# board, Heath has beat me to it. I'm firmly convinced he's really an AI plugged into both the MSDN library and CodeProject.
Keep it up, Heath.
Jeremy Kimball
|
|
|
|
|
|
Heath Stewart wrote:
knowing exactly where to look for things (or how to research things I don't remember / know)
I can't emphasize the above enough to those who are getting into or planning on getting into the coding (or really, ANY field). It is not what you know. It is how fast you can learn it.
Jeremy K.
(just for the helluvit
GAT/E/CS d- s:-- a- C++++$ !U P+ L+ !E W+++$ N++ o? K- w+++$ O- M-- V PS+ PE++ Y+ PGP
t 5 X+ R+ tv+ b++++ DI++++ D++ G e++ h--- r++ x**
|
|
|
|
|
I agree, Heath is the man! Not only does he answer most questions, but he provides clear and thorough explanations.
Kudos to you Heath!
Regards,
Alvaro
He who laughs last, thinks slowest.
|
|
|
|
|
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
|
|
|
|