Event loop when saving Task item in event handler

M

Mustafa

Hi all,

Please go through my problem and see if you can help me out..

The scenario is like this, suppose you have a text box and you
registered an event Handler on TextChanged Event like

this.textBox1.TextChanged += new
System.EventHandler(this.textBox1_TextChanged);

But if I change the Text value of this TextBox inside this TextChanged
event hanlder itself, It will create a loop, because as soon as I
change the text value, TextChange Event will fire, which will invoke
the event Handler, So to avoide this loop, inside the event handler
first i will remove the event handler on the TextChanged Event, modify
the text value and again register the event handler as shown in the
below code...

private void textBox1_TextChanged(object sender, EventArgs e)
{
this.textBox1.TextChanged -= this.textBox1_TextChanged; //
Remove Handler
this.textBox1.Text = System.DateTime.Now.ToString(); //
Update Data
this.textBox1.TextChanged += this.textBox1_TextChanged; //
Add Handler
}

this is working fine for UI objects like TextBox. But I want simulate
this functionality for Outlook Tasks Items some thing like shown
below..

using OL = Microsoft.office.Interopservices.Outlook;

class TestOutlook
{
OL.Application App = null;
OL.NameSpace Ns = null;
OL.MAPIFolder Tasks = null;

private void InitializeOutllok()
{
App = new OL.Application();
Ns = App.GetNamespace("MAPI");
Tasks =
Ns .GetDefaultFolder(OL.OlDefaultFolders.olFolderTasks);

Tasks.Items.ItemChange += Items_ItemChange; // Register Event
handler
}

private void Items_ItemChange(Object pItem)
{
OL.TaskItem UpdatedTask = null;
try
{

Tasks.Items.ItemChange -= Items_ItemChange; // Remove
Handler
OL.TaskItem UpdatedTask = (OL.TaskItem) pItem; // Update it
UpdatedTask.DueDate = System.DateTime.Now;
UpdatedTask.Save();
Tasks.Items.ItemChange += Items_ItemChange; // Add Handler
}
catch(Exception Ex)
{

}
finally
{

System.Runtime.InteropServices.Marshal.ReleaseComObject(pItem);

System.Runtime.InteropServices.Marshal.ReleaseComObject(UpdatedTask);
}
}

}

But I am unable to simulate this for Outlook Tasks Items(Folder)

Regards
Mohamed Mustafa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top