A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Event loop when saving Task item in event handler



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old August 8th 08, 11:46 AM posted to microsoft.public.outlook.program_addins
Mustafa
external usenet poster
 
Posts: 1
Default Event loop when saving Task item in event handler

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.olFolderTask s);

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.ReleaseComO bject(pItem);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(UpdatedTask);
}
}

}

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

Regards
Mohamed Mustafa
Ads
  #2  
Old August 8th 08, 06:24 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Event loop when saving Task item in event handler

See my reply in com.add-ins.
Please do not multipost.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Mustafa" wrote in message
...
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.olFolderTask s);

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.ReleaseComO bject(pItem);

System.Runtime.InteropServices.Marshal.ReleaseComO bject(UpdatedTask);
}
}

}

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

Regards
Mohamed Mustafa



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Before delete mail item Event Handler RAMS Outlook - Using Forms 3 March 3rd 08 01:38 PM
AdvancedSearchComplete event handler nana Outlook and VBA 3 June 30th 07 06:10 AM
event handler for changes to TO CC and BCC properties of mailitem epsilon_9 Outlook and VBA 3 January 15th 07 03:14 PM
Event Handler for Folder Selected [email protected] Add-ins for Outlook 6 May 24th 06 10:44 PM
Handling Task Item Delete Event AtulSureka Outlook - Using Forms 0 January 24th 06 10:25 AM


All times are GMT +1. The time now is 02:08 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.