Click here to Skip to main content
15,120,478 members
Home / Discussions / C#
   

C#

 
QuestionHow to write events in event log using Log4net Pin
venkatpappu31-Jan-13 22:28
Membervenkatpappu31-Jan-13 22:28 
AnswerRe: How to write events in event log using Log4net Pin
Richard MacCutchan31-Jan-13 23:11
mveRichard MacCutchan31-Jan-13 23:11 
QuestionThread.Abort - using and lock statement Pin
devvvy31-Jan-13 16:49
Memberdevvvy31-Jan-13 16:49 
AnswerRe: Thread.Abort - using and lock statement Pin
Dave Kreskowiak31-Jan-13 18:53
mveDave Kreskowiak31-Jan-13 18:53 
GeneralRe: Thread.Abort - using and lock statement Pin
devvvy31-Jan-13 18:59
Memberdevvvy31-Jan-13 18:59 
GeneralRe: Thread.Abort - using and lock statement Pin
Dave Kreskowiak31-Jan-13 20:05
mveDave Kreskowiak31-Jan-13 20:05 
GeneralRe: Thread.Abort - using and lock statement Pin
devvvy31-Jan-13 20:07
Memberdevvvy31-Jan-13 20:07 
GeneralRe: Thread.Abort - using and lock statement Pin
devvvy6-Nov-13 18:13
Memberdevvvy6-Nov-13 18:13 
Looks like M$ fixed that issue with releasing lock - I tested on Windows 8 64 bit zero miss.

Looks like we can conclude:
a. using/lock statements both compatible with Thread.Abort that both would release the resource before thread is dead.
b. Thread.Abort is no longer Evil (If all resources created on the Thread - user remember to release in catch or finally block)

<br />
class Program<br />
    {<br />
        static object obj = new object();<br />
<br />
        static void Main(string[] args)<br />
        {            <br />
            try<br />
            {<br />
                for (int i = 0; i < 1000; i++)<br />
                {<br />
                    Thread thRun = new Thread(new ThreadStart(ThreadFunc));<br />
                    thRun.Start();<br />
<br />
                    Thread.Sleep(300);<br />
<br />
                    thRun.Abort();<br />
<br />
                    lock (obj) // IF ThreadFunc didn't release lock on obj properly, then you wouldnt see following line<br />
                    {<br />
                        Console.WriteLine(i + ": Done locking obj from main");<br />
                    }<br />
                }<br />
<br />
                Console.WriteLine("Hit any key to exit");<br />
                Console.ReadLine();<br />
            }<br />
            catch (Exception Ex)<br />
            {<br />
                Console.WriteLine("Error in main: " + Ex.Message);<br />
            }<br />
<br />
            return;<br />
        }<br />
<br />
        static void ThreadFunc()<br />
        {<br />
            lock (obj)<br />
            {<br />
                using (DataContainer SomeContainer = new DataContainer())<br />
                {<br />
                    Console.WriteLine("ThreadFunc lock begins");<br />
                    Thread.Sleep(1000 * 10);<br />
                }<br />
            }<br />
            Console.WriteLine("ThreadFunc lock released");<br />
<br />
            return;<br />
        }<br />
    }<br />
<br />
    class DataContainer : IDisposable<br />
    {<br />
        protected bool m_isDisposed = false;<br />
<br />
        public void Dispose()<br />
        {<br />
            Dispose(true);<br />
            GC.SuppressFinalize(this);<br />
        }<br />
<br />
        ~DataContainer()<br />
        { // finalizer<br />
            Dispose(false);<br />
        }<br />
<br />
        protected virtual void Dispose(bool disposing)<br />
        {<br />
            Console.WriteLine("DataContainer.Dispose: " + disposing);<br />
<br />
            if (m_isDisposed)<br />
                return;<br />
<br />
            if (disposing)<br />
            {<br />
                // Dispose managed data<br />
                //m_managedData.Dispose();<br />
            }<br />
            // Free unmanaged data<br />
            //DataProvider.DeleteUnmanagedData(m_unmanagedData);<br />
            m_isDisposed = true;<br />
        }<br />
    }<br />

dev

Questionbuild C# as windows app Pin
dcof31-Jan-13 13:12
Memberdcof31-Jan-13 13:12 
AnswerRe: build C# as windows app Pin
Mycroft Holmes31-Jan-13 14:51
professionalMycroft Holmes31-Jan-13 14:51 
AnswerRe: build C# as windows app Pin
Dave Kreskowiak31-Jan-13 15:53
mveDave Kreskowiak31-Jan-13 15:53 
AnswerRe: build C# as windows app Pin
Abhinav S31-Jan-13 23:37
MemberAbhinav S31-Jan-13 23:37 
AnswerRe: build C# as windows app Pin
Pete O'Hanlon1-Feb-13 0:40
mvePete O'Hanlon1-Feb-13 0:40 
QuestionC# and ADP (Automatic Data Processing) integration Pin
Dan_YYC31-Jan-13 6:18
MemberDan_YYC31-Jan-13 6:18 
AnswerRe: C# and ADP (Automatic Data Processing) integration Pin
Dan_YYC4-Feb-13 4:56
MemberDan_YYC4-Feb-13 4:56 
QuestionAuto relocate a label Pin
justcop31-Jan-13 5:41
Memberjustcop31-Jan-13 5:41 
AnswerRe: Auto relocate a label Pin
Abhinav S31-Jan-13 7:13
MemberAbhinav S31-Jan-13 7:13 
AnswerRe: Auto relocate a label Pin
Dave Kreskowiak31-Jan-13 8:02
mveDave Kreskowiak31-Jan-13 8:02 
AnswerRe: Auto relocate a label Pin
Eddy Vluggen31-Jan-13 11:22
professionalEddy Vluggen31-Jan-13 11:22 
QuestionUpload files over HTTPS Pin
Edis Husic31-Jan-13 2:37
MemberEdis Husic31-Jan-13 2:37 
QuestionADAM LDAP Authentification via user distinguishedName Pin
mappy7501730-Jan-13 23:41
Membermappy7501730-Jan-13 23:41 
QuestionSubreport Pin
theezin30-Jan-13 23:16
Membertheezin30-Jan-13 23:16 
AnswerRe: Subreport Pin
Pete O'Hanlon30-Jan-13 23:22
mvePete O'Hanlon30-Jan-13 23:22 
QuestionHow to write c# version of Delphi's Abort procedure Pin
Xiaoming Qian30-Jan-13 19:46
MemberXiaoming Qian30-Jan-13 19:46 
AnswerRe: How to write c# version of Delphi's Abort procedure Pin
Richard MacCutchan30-Jan-13 23:07
mveRichard MacCutchan30-Jan-13 23:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.