|
Are you using a Windows Form timer? IIRC, System.Timers.Timer has an elapsed event, not a tick event but I could be wrong.
|
|
|
|
|
I am. I picked it from the toolbox and dropped in the design page. Am I using the wrong timer? If so, please advice.
Steve C.
kstv@netzero.net
|
|
|
|
|
Well, I'm guessing your windows service doesn't have a form so I'm not sure Windows.Forms.Timer would work, if I were you I'd try using System.Timers.Timer, it might not solve your problem but you never know...
|
|
|
|
|
Thank you for the help. The timer is now working.
Steve C.
kstv@netzero.net
|
|
|
|
|
astv wrote: Am I using the wrong timer?
yes you are. A Forms Timer is great for WinForm apps as it ticks on the GUI thread.
Without a Form, do you have a message pump at all?
Try using a Threading.Timer or a Timers.Timer (not sure which would work/work best for you; they invented that great "documentation" thingy for such purposes).
and make sure your Elapsed handler does call the email code.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thank you for the help. The timer is working and I am inserting the send email process.
Steve C.
kstv@netzero.net
|
|
|
|
|
Try using the timer from the System.Timers namespace.
private System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 60000;
timer.Elapsed += new ElapsedEventHandler(onTimer_Elapsed);
timer.Start();
private void onTimer_Elapsed(object sender, ElapsedEventArgs e)
{
}
|
|
|
|
|
Thank you for the help. The timer object instantiation was very helpful. I'll remember not to use the form timer next time.
Steve C.
kstv@netzero.net
|
|
|
|
|
Use Timer from System.Timers namespace. And call SendEmailNotification method in the elapsed event.
|
|
|
|
|
I'm trying to make a helpdesk application that processes incoming emails for a specific account. I'm having trouble with the Itemadd event. It will quit after receiving around 17-28 emails and I have to restart the program. I have not found much online about this issue besides it's probably a scope problem and the GC is killing the event. I did make a stripped down version of the program which seems to work fine but I dont know why it works when this one doesn't.
In the load function of the form im using this for getting the namespace and the correct store. All variables not initialized in the code are private.
If I comment out treeview1_add function it'll work up to 30 emails which probably means it's working. However I do not know why commenting out that function will make it work and I need that function.
thank you for any help you can give me.
<code>
void form_load()
{
mapi = outlookapp.GetNamespace("MAPI");
int helpdeskcount = 1;
int count = 1;
while (count <= mapi.Stores.Count)
{
if (mapi.Stores[count].DisplayName.Contains("Storename"))
{
helpdeskcount = count;
count = mapi.Stores.Count;
}
count++;
}
oinbox = mapi.Folders[helpdeskcount];
helpdesk = oinbox.Folders["Inbox"];
helpdesk.Items.ItemAdd += new ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}
void Items_ItemAdd(object Item)
{
load_unassigned();
counter();
}
void counter()
{
if (this.InvokeRequired)
{
this.Invoke(new Invoker_no_strings(this.counter));
}
else
{
int count = int.Parse(label1.Text);
count++;
label1.Text = count.ToString();
}
}
public void load_unassigned()
{
tree_node_clear(treeView1);
incident_load = new tbl_incidents_BLL();
tempnode = null;
arrtemp = incident_load.loadallunassigned();
int length = arrtemp.GetLength(0);
int count = 0;
while (count < length)
{
treeview1_add(arrtemp[count, 0], arrtemp[count, 1] + ": " + arrtemp[count, 3]);
count++;
}
}
public void tree_node_clear(TreeView temp)
{
if (this.InvokeRequired)
{
this.Invoke(new tree_clear(this.tree_node_clear), temp);
}
else
{
temp.Nodes.Clear();
}
}
public void treeview1_add(string id, string value)
{
if (this.InvokeRequired)
{
this.Invoke(new treeview1_add_delegate(this.treeview1_add), id, value);
}
else
{
treeView1.Nodes.Add(id, value);
}
}
}</code>
ghoster
modified on Wednesday, July 15, 2009 12:04 PM
|
|
|
|
|
Hi,
so you suspect the ItemAdd event, however you did not show the relevant code, i.e. the declaration of the event, and the code that causes it to execute.
Besides the event getting collected, I have two usual suspects for you:
1.
maybe you execute the event on a thread other than the main/GUI thread, so the delegates would not be allowed to touch any Control. You are correctly using the InvokeRequired pattern on some operations, how about the tbl_incidents_BLL constructor and incident_load.loadallunassigned?
BTW: I would consider moving the InvokeRequired pattern upstream, so it serves all the subactions in Items_ItemAdd.
2.
maybe you are getting an exception somewhere, which you don't handle at all. Or worse, you have an empty catch block. Check your code, make sure to put the top-level method of each thread inside a single potentially huge try-catch where the catch block logs and shows Exception.ToString
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello,
Declaration of the objects to the itemAdd event are
private Microsoft.Office.Interop.Outlook.Application outlookapp = new Microsoft.Office.Interop.Outlook.Application();
private Microsoft.Office.Interop.Outlook.MAPIFolder oinbox = null;
private Microsoft.Office.Interop.Outlook.MAPIFolder helpdesk = null;
private Microsoft.Office.Interop.Outlook.MAPIFolder omessages = null;
For the code that causes it to execute, correct me if im wrong, the ItemAddEventHander that executes the Items_ItemAdd function
oinbox = mapi.Folders[helpdeskcount];
helpdesk = oinbox.Folders["Inbox"];
helpdesk.Items.ItemAdd += new ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
1.
You're right I'm not using the invoke for the tbl_incidents_BLL constructor or the loadallunassigned. Ill have to try adding that in the loadunassigned function. Also I did add InvokeRequired pattern to Items_ItemAdd function so all subactions are served.
2.
Heh yeah i've been trying add try-catches everywhere but haven't gotten any yet. Also the form that im having trouble on isn't the main form. It's called when an administrator opens it. I should have said about that earlier. I just added the try-catch and ran the program. Same problem and no error, but im weak on try-catch scope, if there's an error anywhere on the administrator_form would this try-catch show it or not b/c of threading?
public partial class Form1 : Form<br />
{<br />
public tbl_administrators_BLL logged_in_admin = null;<br />
private Form administrator_form = null;<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
logged_in_admin = new tbl_administrators_BLL();<br />
logged_in_admin.loadtoclass(System.Environment.UserName);<br />
if (logged_in_admin.getid() == -1)<br />
{<br />
this.WindowState = FormWindowState.Minimized;<br />
Form user_form = new User();<br />
user_form.Show();<br />
}<br />
else<br />
{<br />
<br />
this.WindowState = FormWindowState.Minimized;<br />
administrator_form = new Administrator();<br />
administrator_form.Show();<br />
}<br />
this.Hide();<br />
this.Visible = false;<br />
}<br />
catch (System.Exception ex)<br />
{<br />
MessageBox.Show(ex.ToString());<br />
}<br />
}<br />
}
thanks
|
|
|
|
|
OK, my advice is:
1.
to have one big try-catch on every thread, so basically the first thing a thread does is enter its try block. For the main thread that would be the static Main() method, for any other thread/ThreadPoolWorkItem/BackgroundWorker that would be the method you pass them; for asynchronous callbacks (Timers/SerialPorts/other input-output) that would be the handlers you provide.
All the above are safety nets, they don't solve any problem your app may encounter, but at least they would inform you, the developer.
2.
add lots of logging, either to a file or to a Console (not to EventViewer, not to the GUI); have each line include current time (up to the millisecond if relevant) the ManagedThreadId, one text message, and some relevant data (such as mail count).
If logging to file, I tend to use File.AppendText, so basically the file is closed all the time, and a crash does not keep me from reading the most recent messages.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Yeah i was hoping for at least an error message.
Ill try the logging see what i can find. One thing i did find was the Microsoft.Office.Interop.Outlook.ItemEvents_EventProvider.Finalize()
fired near the end.
thank you again for your help I have a much better idea on how to find the problem
|
|
|
|
|
Afternoon all,
I'm looking for advice or opinions on the best placement of GC.SuppressFinalize for reference counted objects.
The "standard" dispose pattern has the call in the public Dispose method :-
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
However, for objects with reference counts I'm inclined to put it in the protected Dispose :-
protected void Dispose(bool _fulldispose)
{
if (!m_Disposed)
{
if (RemoveRef() == 0)
{
if (_fulldispose)
{
GC.SuppressFinalize(this);
etc...
My reasoning is that if not all references are explicitly disposed, then the finaliser will still be needed to do the clean up. (Although in our system all objects with unmanaged components should be explicitly disposed, so that may be academic.)
There are lots of discussions about Dispose, IDisposable, SuppressFinalize etc. out on the net, but very few deal with the ref counted situation, so I'm open to any thoughts or advice...
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
I am trying to represent a virtual joystick on a User Interface although im having trouble trying to represent the 4 different axis of the joystick and the click on the top.
The best i have come up with is a custom control to represent:
x and y axis (using drag a cross in a circle technique)
up and down (using a trackbar)
button click (using a button)
In real life all of these can be used at the same time however cannot with my combination of controls. Does anyone have any ideas how to represent the 4 axis and click functionality
Thanx George
|
|
|
|
|
The best I can suggest is to capture the mouse so you don't need to drag, replace the trackbar with the mousewheel, and use the keyboard for the button. Going to be a bit of a bitch for the user what ever you do - I would prefer using a real joystick?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
That sounds like the best solution.
Thanx for the help.
It would be annoying for the user but i am an apprentice and this is a training project to try and create a virtual MCU so need to give it a go.
The project will eventually use a real one but for now it needs to be a virtual representation.
|
|
|
|
|
OriginalGriff wrote: and use the keyboard for the button
Or use the mouse button?
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
Try it on yours - move it, twiddle with the scroll wheel, and press the button - it's like pat your head / rub your stomach! Keyboard means you can divide the work between two hands, and makes it simpler...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
OriginalGriff wrote: Keyboard means you can divide the work between two hands, and makes it simpler...
Spoken like a true PC gamer...
Of course the easy answer is to just plug in an XBox joypad - that's what I do
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
molesworth wrote: Spoken like a true PC gamer
I did indeed spend a considerable amount of time with a subtle little game back in the nineties. "Doom" I think it was called... Ate most of my life for about three years. Or was it four? Lost track of time a bit back then due to lack of sleep.
molesworth wrote: the easy answer is to just plug in an XBox joypad
My 360 is wireless, so that wouldn't help if I was doing the project. But Saitek joysticks aren't too expensive anyway and they can take some abuse.
[edit]changed: "Saitek joysticks are too expensive..." oops![/edit]
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
How to get the control property 'Handle' and 'Name' from another .NET application window?
|
|
|
|
|
Why do you need this?? As it stands, your questions just screams "bad design". Controlling another applciation through window messages is not the best way to go about it.
|
|
|
|
|
Hello,
I am in searchof a method that converts my HTML input into RTF. I don't want to have any 3rd party tools to do it.
Can anyone help me to achieve this?
Thanks in advance.
Sebastian
|
|
|
|