Question : Exchange 2007 EWS API change appointment

Hi
I have a strange problem with the following code:

/* CODE SNIP BEGIN */
//Get existing Exchange appointment
Appointment exchangeAppointment = Appointment.Bind(service, new ItemId(xalAppointment.EXCHANGEITEMID));

//Here comes the puzzel - if I run the code without the sleep - the update does not take place. If however I keep the sleep the update does take place - why ???
Thread.Sleep(1000);

//Update the content of the appointment
mapper.FillAppointment(xalAppointment, exchangeAppointment, email);

//Update Exchange
exchangeAppointment.Update(ConflictResolutionMode.AlwaysOverwrite);

/* CODE SNIP END */

The question is - why do I need the sleep ???
Can I do the same job with no sleep (som other way) ???
I lots of updates to process, so I realy do not want to waste time sleeping if it can be avoided.

Looking forward to getting help - Kaj Bromose
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
/* CODE SNIP BEGIN */
//Get exsisting Exchange appointment
Appointment exchangeAppointment = Appointment.Bind(service, new ItemId(xalAppointment.EXCHANGEITEMID));
 
//Here comes the puzzel - if I run the code without the sleep - the update does not take place. If however I keep the sleep the update does take place - why ???
Thread.Sleep(1000);
 
//Update the content of the appointment
mapper.FillAppointment(xalAppointment, exchangeAppointment, email);
 
//Update Exchange
exchangeAppointment.Update(ConflictResolutionMode.AlwaysOverwrite);
 
/* CODE SNIP END */

Answer : Exchange 2007 EWS API change appointment

Well I have not done what you are doing, but what I have done to change/update an appointment is the following code - no sleep needed:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
// Find the item (exchange appt) you want to update.  Here is an example to find an appointment using a custom field
ItemIdType id; 
// Form the FindItem request
FindItemType request = new FindItemType();
request.Traversal = ItemQueryTraversalType.Shallow; 
// Define which item properties are returned in the response
request.ItemShape = new ItemResponseShapeType();
request.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly; 
// Identify which folders to search to find items
DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
folderIDArray[0] = new DistinguishedFolderIdType();
folderIDArray[0].Id = DistinguishedFolderIdNameType.calendar;
folderIDArray[0].Mailbox = new EmailAddressType();
folderIDArray[0].Mailbox.EmailAddress = accountId; // accountId is the exchange email account 
// Add folders to request
request.ParentFolderIds = folderIDArray; 
// Define Custom field
PathToExtendedFieldType pteft = new PathToExtendedFieldType();
pteft.PropertyName = "CustomField";
pteft.PropertyType = MapiPropertyTypeType.String;
pteft.DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings;
pteft.DistinguishedPropertySetIdSpecified = true; 
// Define restrictions
AndType andRestrictions = new AndType();
andRestrictions.Items = new SearchExpressionType[2]; 
// Define equal to series Id restriction
IsEqualToType isEqual = new IsEqualToType();
isEqual.FieldURIOrConstant = new FieldURIOrConstantType();
isEqual.FieldURIOrConstant.Item = new ConstantValueType();
(isEqual.FieldURIOrConstant.Item as ConstantValueType).Value = "custom field value"; 
isEqual.Item = pteft; 
andRestrictions.Items[0] = isEqual; 
// Define greater than today restriction
// Set condition to be only future
IsGreaterThanOrEqualToType greaterOrEqual = new IsGreaterThanOrEqualToType();
greaterOrEqual.FieldURIOrConstant = new FieldURIOrConstantType();
greaterOrEqual.FieldURIOrConstant.Item = new ConstantValueType();
(greaterOrEqual.FieldURIOrConstant.Item as ConstantValueType).Value = DateTime.Now.Date.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ssZ"); 
// Define Start Date field as the field we are applying condition to
PathToUnindexedFieldType ptuft = new PathToUnindexedFieldType();
ptuft.FieldURI = UnindexedFieldURIType.calendarStart;
greaterOrEqual.Item = ptuft; 
andRestrictions.Items[1] = greaterOrEqual; 
request.Restriction = new RestrictionType();
request.Restriction.Item = isEqual; 
// Send the request and get the response
FindItemResponseType response = esb.FindItem(request); 
// make sure response is successfull
if(response.ResponseMessages.Items.Length == 1 && response.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
{
	ItemType[] items = ((ArrayOfRealItemsType)((FindItemResponseMessageType)response.ResponseMessages.Items[0]).RootFolder.Item).Items; 
	if(items != null && items.Length == 1)
	{
		id = (items[0].ItemId);
	}
} 

// Now you can do the update
UpdateItemType updateItem = new UpdateItemType();
updateItem.MessageDisposition = MessageDispositionType.SaveOnly;
updateItem.MessageDispositionSpecified = true; 
// SendMeetingInvitations attribute is required for calendar items.
updateItem.SendMeetingInvitationsOrCancellations = CalendarItemUpdateOperationType.SendToNone;
updateItem.SendMeetingInvitationsOrCancellationsSpecified = true; 

updateItem.ItemChanges = new ItemChangeType[1];
updateItem.ItemChanges[0] = new ItemChangeType();
updateItem.ItemChanges[0].Item = id;
updateItem.ItemChanges[0].Updates = new ItemChangeDescriptionType[2]; 
SetItemFieldType startItem = new SetItemFieldType();
startItem.Item = new PathToUnindexedFieldType();
((PathToUnindexedFieldType)startItem.Item).FieldURI = UnindexedFieldURIType.calendarStart; 
startItem.Item1 = new CalendarItemType();
((CalendarItemType)startItem.Item1).Start = startDate;
((CalendarItemType)startItem.Item1).StartSpecified = true; 
updateItem.ItemChanges[0].Updates[0] = startItem; 
SetItemFieldType endItem = new SetItemFieldType();
endItem.Item = new PathToUnindexedFieldType();
((PathToUnindexedFieldType)endItem.Item).FieldURI = UnindexedFieldURIType.calendarEnd; 
endItem.Item1 = new CalendarItemType();
((CalendarItemType)endItem.Item1).End = endDate;
((CalendarItemType)endItem.Item1).EndSpecified = true; 
updateItem.ItemChanges[0].Updates[1] = endItem; 
// Send the request and get the response
UpdateItemResponseType response = esb.UpdateItem(updateItem);
Random Solutions  
 
programming4us programming4us