AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 27.05.2009, 23:16   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
gatesasbait: Logging independently of transaction scope by using a separate thread in Dynamics AX
Источник: http://gatesasbait.spaces.live.com/B...B9F5!399.entry
==============


Good morning,

Continuing on the topic of good ideas to palliate lazy code designs (ref: previous post on runbuf()), I wanted to discuss a possible way to write to a table from inside a TTS (between a begin and a commit) without being rolled back if an error is thrown or if a ttsabort is called.

Doing this is definitely not best practice, but it was extremely useful for me when I wanted to log information to a table from inside a TTS that would throw errors on occasion where catching was not behaving ideally because of an encompassing TTS (I’ll follow up on that on another post).

So basically, the idea I had is to launch a separate thread only for logging, this would effectively isolate the table insert from the encompassing TTS and would not be rolled back on error in the originating thread. So the logging would always occur regardless of errors.

Here’s a sample of the code:


X++:
public class LogThread 
{
public server static void logThreadWorker(Thread t)
{
 LogTable log;
 ;  
 [log.ParmId,
 log.XmlRequest,
 log.XmlResponse] = t.getInputParm();
 log.insert();
}
}  
//Use a separate thread to survive a ttsabort
public server static void logUsingThread(
 str _parmId,
 str _xml1,
 str _xml2)
{
 Thread thread;
 ExecutePermission permission;
 ;  
 permission = new ExecutePermission();
 if (!permission)
 {
 return;
 }  
 permission.assert();  
 // BP deviation documented.
 thread = new Thread();
 if (thread)
 {
 thread.removeOnComplete(true);
 thread.setInputParm([_parmId, _xml1, _xml2]);
 thread.run(classnum(LogThread),
 staticmethodstr(LogThread, logThreadWorker));
 }  
 CodeAccessPermission::revertAssert();
}  //This method is the entry point for logging, and is called from a series of transactions and operations that might fail.
//It is called from inside a large TTS encompassing multiple business processes.
protected void log(
 MyWebservice.WebServiceWrapper _webServiceWrapper)
{
 ; 

  LogTable::logUsingThread(
 this.parmId(), //I had a parmId for every request to the webService
 _webServiceWrapper.get_LastXmlRequestDoc(),
 _webServiceWrapper.get_LastXmlResponseDoc());
}



Источник: http://gatesasbait.spaces.live.com/B...B9F5!399.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Developer for Microsoft Dynamics AX Certification Roadmap Blog bot DAX Blogs 1 13.05.2009 16:17
Dynamics AX: Managing Your Supply Chain Using Microsoft Dynamics AX 2009 - Book Review Blog bot DAX Blogs 0 31.03.2009 23:06
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
Inside Dynamics AX 4.0: Transaction Semantics Blog bot DAX Blogs 0 31.10.2007 23:40
Inside Dynamics AX 4.0: Usage Scenarios Blog bot DAX Blogs 0 04.10.2007 05:15

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 20:29.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.