Click here to Skip to main content
16,008,299 members
Home / Discussions / C#
   

C#

 
Questiontimeout expired.timeout period elapsed prior to completion of the operation or the server is not responding [modified] Pin
ayyp7-Jul-06 3:30
ayyp7-Jul-06 3:30 
AnswerRe: timeout expired.timeout period elapsed prior to completion of the operation or the server is not responding Pin
Judah Gabriel Himango7-Jul-06 4:34
sponsorJudah Gabriel Himango7-Jul-06 4:34 
GeneralRe: timeout expired.timeout period elapsed prior to completion of the operation or the server is not responding Pin
ayyp7-Jul-06 18:41
ayyp7-Jul-06 18:41 
QuestionDataView.Find(object value) Pin
peshawarcoder7-Jul-06 3:02
peshawarcoder7-Jul-06 3:02 
QuestionDisabling "X" button in WinForm Pin
stancrm7-Jul-06 2:37
stancrm7-Jul-06 2:37 
AnswerRe: Disabling "X" button in WinForm Pin
Not Active7-Jul-06 2:58
mentorNot Active7-Jul-06 2:58 
AnswerRe: Disabling "X" button in WinForm [modified] Pin
Anh_Tuan7-Jul-06 3:02
Anh_Tuan7-Jul-06 3:02 
QuestionError : Cannot write to a closed TextWriter Pin
adityap7-Jul-06 2:01
adityap7-Jul-06 2:01 
Hi,
I am getting the above mentioned error while excuting the following simple example ( relating to dispose and finalize). Exact output is also attached after the program.
Can any body explain me the cause for this?

Thanks a lot in advance

//#PROGRAM
using System;

namespace test
{
//Base.cs
public class Base : IDisposable
{
private bool disposed = false;
private readonly int id;
public int ID
{
get
{
return id;
}
}
public Base(int theID)
{
id = theID;
}
public void Disp()
{
Console.WriteLine("You can run me after disposing{0}",id);
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
Console.WriteLine("Base Cleaning up managed resources on {0}",id);
// Code to clean up managed resources
}
Console.WriteLine("Base Cleaning up unmanaged resources on {0}", id);
// Code to clean up unmanaged resources
}
disposed = true;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

~Base()
{
//Following line gives error for object 2
Console.WriteLine("*** Finalize called on Base {0}", id);
Dispose(false);
}
}


//Derived.cs
public class Derived : test.Base
{
private bool disposed = false;

public Derived(int theID) : base(theID) {}

protected override void Dispose(bool disposing)
{
if (!disposed)
{
try
{
if (disposing)
{
Console.WriteLine("Derived Cleaning up managed resources");
// Code to clean up managed resources
}
Console.WriteLine("Derived Cleaning up unmanaged resources");
// Code to clean up unmanaged resources
}
finally
{
base.Dispose(disposing);
}
}
disposed = true;
}
}


//Test.cs
class Test
{
[STAThread]
static void Main(string[] args)
{
Derived object1 = new Derived(1);
Derived object2 = new Derived(2);

object1.Dispose();

}
}
}

//#OUTPUT

Derived Cleaning up managed resources
Derived Cleaning up unmanaged resources
Base Cleaning up managed resources on 1
Base Cleaning up unmanaged resources on 1

An unhandled exception of type 'System.ObjectDisposedException' occurred in mscorlib.dll

Additional information: Cannot write to a closed TextWriter.

Unhandled Exception: System.ObjectDisposedException: Cannot write to a closed TextWriter.
at System.IO.__Error.WriterClosed()
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
at System.IO.TextWriter.WriteLine(String value)
at System.IO.TextWriter.WriteLine(String format, Object arg0)
at System.IO.SyncTextWriter.WriteLine(String format, Object arg0)
at System.Console.WriteLine(String format, Object arg0)
at test.Base.Dispose(Boolean disposing)
at test.Derived.Dispose(Boolean disposing)
at test.Base.Finalize()The program '[3476] test.exe' has exited with code 0 (0x0).

Note that if you comment the lines relating object1, the program runs fine without any exception.
//#OUTPUT WHEN line 1 & 3 are commented in Main()
Derived Cleaning up unmanaged resources
Base Cleaning up unmanaged resources on 2


techno_adi
AnswerRe: Error : Cannot write to a closed TextWriter Pin
Judah Gabriel Himango7-Jul-06 4:39
sponsorJudah Gabriel Himango7-Jul-06 4:39 
AnswerRe: Error : Cannot write to a closed TextWriter Pin
Judah Gabriel Himango7-Jul-06 4:40
sponsorJudah Gabriel Himango7-Jul-06 4:40 
GeneralProblem - Re: Error : Cannot write to a closed TextWriter [modified] Pin
adityap9-Jul-06 20:00
adityap9-Jul-06 20:00 
QuestionPage Timers Pin
Brendan Vogt7-Jul-06 1:46
Brendan Vogt7-Jul-06 1:46 
AnswerRe: Page Timers Pin
Guffa7-Jul-06 3:57
Guffa7-Jul-06 3:57 
AnswerRe: Page Timers Pin
Dustin Metzgar7-Jul-06 4:04
Dustin Metzgar7-Jul-06 4:04 
QuestionCreating an options dialog for my WinApp. Pin
anderslundsgard7-Jul-06 1:14
anderslundsgard7-Jul-06 1:14 
AnswerRe: Creating an options dialog for my WinApp. Pin
Robert Rohde7-Jul-06 4:37
Robert Rohde7-Jul-06 4:37 
QuestionHow to get data from text box respective of text position ? Pin
praveenqwe7-Jul-06 0:52
praveenqwe7-Jul-06 0:52 
AnswerRe: How to get data from text box respective of text position ? Pin
stancrm7-Jul-06 1:03
stancrm7-Jul-06 1:03 
QuestionHow to make a Class object global?? Pin
suguimoto7-Jul-06 0:25
suguimoto7-Jul-06 0:25 
AnswerRe: How to make a Class object global?? [modified] Pin
psamy7-Jul-06 0:38
psamy7-Jul-06 0:38 
AnswerRe: How to make a Class object global?? Pin
Brendan Vogt7-Jul-06 0:42
Brendan Vogt7-Jul-06 0:42 
AnswerRe: How to make a Class object global?? Pin
Guffa7-Jul-06 3:43
Guffa7-Jul-06 3:43 
GeneralHeh, doesn't work Pin
Ennis Ray Lynch, Jr.7-Jul-06 8:23
Ennis Ray Lynch, Jr.7-Jul-06 8:23 
AnswerRe: Heh, doesn't work Pin
Guffa7-Jul-06 23:45
Guffa7-Jul-06 23:45 
QuestionRichTextBoxControl cursor position Pin
Radu Sorin7-Jul-06 0:16
Radu Sorin7-Jul-06 0:16 

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.