Showing posts with label location. Show all posts
Showing posts with label location. Show all posts

Saturday, March 31, 2012

There Is No Source Code Available For The Current Location

Hey,
I have a ASP.NET web application,
And whenever I try to debug a JScript/VBScript block (using- "stop", or
- "debugger;") I get the following error:
"There Is No Source Code Available For The Current Location"
And when I do succeeded debugging the script, I get the same error when
trying to debug a function from an included JS file.
I tried:
restarting the computer
shutting down the computer
restarting the .Net IDE
Clearing the- Temp ASPNET files from the - Microsoft.Net folder (on -
%windir%)
Clearing the IE Temp files
And got no success...
Thanks ahead,

--RamRam wrote:
> Hey,
> I have a ASP.NET web application,
> And whenever I try to debug a JScript/VBScript block (using- "stop",
or
> - "debugger;") I get the following error:
> "There Is No Source Code Available For The Current Location"
> And when I do succeeded debugging the script, I get the same error
when
> trying to debug a function from an included JS file.
> I tried:
> restarting the computer
> shutting down the computer
> restarting the .Net IDE
> Clearing the- Temp ASPNET files from the - Microsoft.Net folder (on -
> %windir%)
> Clearing the IE Temp files
> And got no success...
> Thanks ahead,
> --Ram

Shutdown Visual Studio .NET
Run IISRESET in command window.
Shutdown <YOUR APPLICATION> COM+ applications
Delete <YOUR APPLICATION> temp files found here:
C:\Documents and Settings\<YOUR USER NAME>\VSWebCache
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Tempo rary ASP.NET Files

It worked for me.

T.H.

There is no source code available for the current location

Hello,

I'm new to ASP.net and C#. I have attempted to debug one portion of our Web Application. I then edited some our code and rebuilt the project and now I cannot debug that area in the code. It says "There is no source code available for the current location" and prompts me asking if I want to view the dissambly.

What should I do?

--doc0tis

show us the source and highlite the line where your trying to set the breakpoint.

mcm

There Is No Source Code Available For The Current Location

Hey,
I have a ASP.NET web application,
And whenever I try to debug a JScript/VBScript block (using- "stop", or
- "debugger;") I get the following error:
"There Is No Source Code Available For The Current Location"
And when I do succeeded debugging the script, I get the same error when
trying to debug a function from an included JS file.
I tried:
restarting the computer
shutting down the computer
restarting the .Net IDE
Clearing the- Temp ASPNET files from the - Microsoft.Net folder (on -
%windir%)
Clearing the IE Temp files
And got no success...
Thanks ahead,
--RamRam wrote:
> Hey,
> I have a ASP.NET web application,
> And whenever I try to debug a JScript/VBScript block (using- "stop",
or
> - "debugger;") I get the following error:
> "There Is No Source Code Available For The Current Location"
> And when I do succeeded debugging the script, I get the same error
when
> trying to debug a function from an included JS file.
> I tried:
> restarting the computer
> shutting down the computer
> restarting the .Net IDE
> Clearing the- Temp ASPNET files from the - Microsoft.Net folder (on -
> %windir%)
> Clearing the IE Temp files
> And got no success...
> Thanks ahead,
> --Ram
Shutdown Visual Studio .NET
Run IISRESET in command window.
Shutdown <YOUR APPLICATION> COM+ applications
Delete <YOUR APPLICATION> temp files found here:
C:\Documents and Settings\<YOUR USER NAME>\VSWebCache
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files
It worked for me.
T.H.

There is no source code available for the current location.

I'm debugging my VB.net webapplication, with VS.2005

When I step into the code, I get the following error on this line of code:

ddlServers.DataBind()

"There is no source code available for the current location."

I asks me if I want to show the disassembly.

What goes wrong?

Hi.

where is the code for binding the values to the dropdown..

are u using sqldatasource or coding manually..


I use an ObjectDataSource:

<asp:DropDownList

ID="ddlServers"

runat="server"

style="margin: 10px;"

DataSourceID="ObjectDataSource1"

DataTextField="SERVER_NAME"

DataValueField="SERVER_AND_PORT"

AutoPostBack="True"

meta:resourcekey="ddlServersResource1">

</asp:DropDownList>

<asp:ObjectDataSource

ID="ObjectDataSource1"

runat="server"

SelectMethod="GetServers"

TypeName="Plugin_Manager_BLL.PluginManager"

OldValuesParameterFormatString="original_{0}">

</asp:ObjectDataSource>


as far as I'm aware - you wouldn't need to call the databind() if your ddl has a datasource - this should be done automatically. If you need to re-bind, after a postback for example, why not try to add:

if not page.ispostback then

'do stuff

else

ddl.databind()

end if

maybe try that?


Hi,

Based on my understanding, when you try to step into the code above, you get the error message above. You used ObjectDataSource to bind the control. If I have misunderstood you, please feel free to let me know.

The error message above indicates that the debugger cannot display source code for the current location where execution has stopped. As far as I know, when we use a library without its source code, we cannot show the source code (DataBind method).

To better understand your issue, could you please confirm the following information:

If we create another simple project and bind the DropDownList with ObjectDataSource, does it have the same issue?

Tuesday, March 13, 2012

Thread safety advice

My application uses a singleton static class for writing entries to a log
file. The location and name of the log-file is read from web.config each time
an entry is written, but has the current date inserted into its name. For
example, the string:

c:\inetpub\wwwroot\myapp\log.txt

will be changed to:

c:\inetpub\wwwroot\myapp\log_20060216.txt

However, as we have many concurrent users on the site at once, each
generating hundreds of log file entries a minute, we're finding that multiple
threads are calling the same code at the same time and we're getting filename
with multiple date stamps. Ie:

c:\inetpub\wwwroot\myapp\log_20060216_20060216.txt

I'm sure this is to do with the following code not being thread-safe despite
the "lock" critical section statement:

string sLog_File_Path = ConfigurationManager.AppSettings["logfilepath"];

lock (FoLockObject) {
sLog_File_Path = Path.Combine(Path.GetDirectoryName(sLog_File_Path) ,
Path.GetFileNameWithoutExtension(sLog_File_Path) + "_" +
DateTime.Now.ToString("yyyyMMdd") +
Path.GetExtension(sLog_File_Path));
}

Can anyone offer advice on the correct way to protect code that is
vulnerable to threading issues. I'm aware of synchronization objects such as
Mutex's but am unsure how to use them with static classes. A stright forward
example in C# without being too clever would be very handy

Thanks

BenIs sLog_File_Path local or member variable?
What about FoLockObject?

Unfortunately it' hard to say where is the problem you need to show us full
class.

George.

"Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
news:27A2FF7B-4565-40A5-8D95-CE197DE94166@.microsoft.com...
> My application uses a singleton static class for writing entries to a log
> file. The location and name of the log-file is read from web.config each
> time
> an entry is written, but has the current date inserted into its name. For
> example, the string:
> c:\inetpub\wwwroot\myapp\log.txt
> will be changed to:
> c:\inetpub\wwwroot\myapp\log_20060216.txt
> However, as we have many concurrent users on the site at once, each
> generating hundreds of log file entries a minute, we're finding that
> multiple
> threads are calling the same code at the same time and we're getting
> filename
> with multiple date stamps. Ie:
> c:\inetpub\wwwroot\myapp\log_20060216_20060216.txt
> I'm sure this is to do with the following code not being thread-safe
> despite
> the "lock" critical section statement:
> string sLog_File_Path = ConfigurationManager.AppSettings["logfilepath"];
> lock (FoLockObject) {
> sLog_File_Path = Path.Combine(Path.GetDirectoryName(sLog_File_Path) ,
> Path.GetFileNameWithoutExtension(sLog_File_Path) + "_" +
> DateTime.Now.ToString("yyyyMMdd") +
> Path.GetExtension(sLog_File_Path));
> }
> Can anyone offer advice on the correct way to protect code that is
> vulnerable to threading issues. I'm aware of synchronization objects such
> as
> Mutex's but am unsure how to use them with static classes. A stright
> forward
> example in C# without being too clever would be very handy
> Thanks
> Ben
Here's an abbreviated version of the full class.

public class CLog {
private static string FsLog_File_Path = "";
private static object FoLockObject = new object();

private static void RefreshSettings() {
FsLog_File_Path = ConfigurationSettings.AppSettings["logfilepath"];

lock (FoLockObject) {
FsLog_File_Path =
Path.Combine(Path.GetDirectoryName(FsLog_File_Path ),
Path.GetFileNameWithoutExtension(FsLog_File_Path) + "_" +
DateTime.Now.ToString("yyyyMMdd") +
Path.GetExtension(FsLog_File_Path));
}
}

public static void WriteInfo(string sDescription) {
RefreshSettings();

StreamWriter oStream = null;

try {
if (File.Exists(FsLog_File_Path)) {
oStream = File.AppendText(FsLog_File_Path);
}
else {
oStream = File.CreateText(FsLog_File_Path);
}

oStream.AutoFlush = true;

string sSession = "";
if (HttpContext.Current != null) sSession =
HttpContext.Current.Session.SessionID + " - ";
else sSession = "";

oStream.WriteLine(string.Format("{0} - {1} - {2}{3}",
DateTime.Now.ToString("dd MMM yyy H:mm:ss"), "INFO", sSession,
sDescription));
}
catch (IOException) {

}
finally {
if (oStream != null) oStream.Close();
oStream = null;
}
}
}

"George Ter-Saakov" wrote:

> Is sLog_File_Path local or member variable?
> What about FoLockObject?
> Unfortunately it' hard to say where is the problem you need to show us full
> class.
> George.
>
> "Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
> news:27A2FF7B-4565-40A5-8D95-CE197DE94166@.microsoft.com...
> > My application uses a singleton static class for writing entries to a log
> > file. The location and name of the log-file is read from web.config each
> > time
> > an entry is written, but has the current date inserted into its name. For
> > example, the string:
> > c:\inetpub\wwwroot\myapp\log.txt
> > will be changed to:
> > c:\inetpub\wwwroot\myapp\log_20060216.txt
> > However, as we have many concurrent users on the site at once, each
> > generating hundreds of log file entries a minute, we're finding that
> > multiple
> > threads are calling the same code at the same time and we're getting
> > filename
> > with multiple date stamps. Ie:
> > c:\inetpub\wwwroot\myapp\log_20060216_20060216.txt
> > I'm sure this is to do with the following code not being thread-safe
> > despite
> > the "lock" critical section statement:
> > string sLog_File_Path = ConfigurationManager.AppSettings["logfilepath"];
> > lock (FoLockObject) {
> > sLog_File_Path = Path.Combine(Path.GetDirectoryName(sLog_File_Path) ,
> > Path.GetFileNameWithoutExtension(sLog_File_Path) + "_" +
> > DateTime.Now.ToString("yyyyMMdd") +
> > Path.GetExtension(sLog_File_Path));
> > }
> > Can anyone offer advice on the correct way to protect code that is
> > vulnerable to threading issues. I'm aware of synchronization objects such
> > as
> > Mutex's but am unsure how to use them with static classes. A stright
> > forward
> > example in C# without being too clever would be very handy
> > Thanks
> > Ben
>
You do have a problem in your code.
This line is not thread safe.

FsLog_File_Path = ConfigurationSettings.AppSettings["logfilepath"];

You are modifying the variable while some other thread could have been doing
the code that is in lock {} section.
So move that line inside (but read further)

---------------
I am not sure why your are doing it this way. Because I do not see any gain
in FsLog_File_Path beign global/member variable.
I would rewrite the code to avoid any synchronization

private static void RefreshSettings() {
string sPath =
ConfigurationSettings.AppSettings["logfilepath"];
sPath = Path.Combine(Path.GetDirectoryName(sPath),
Path.GetFileNameWithoutExtension(sPath) + "_" +
DateTime.Now.ToString("yyyyMMdd") +
Path.GetExtension(sPath));
}
}

As you can see all manipulations are made to local variable so you do not
need lock.

--------------------

The only place where you will need to lock is where you are opening the file
and writing to it. Since that is not thread safe.
And this will fail if you try to open/write into file from multiple threads.

George

"Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
news:B6D5463F-61F6-41BB-B39D-7679E2587C0A@.microsoft.com...
> Here's an abbreviated version of the full class.
> public class CLog {
> private static string FsLog_File_Path = "";
> private static object FoLockObject = new object();
> private static void RefreshSettings() {
> FsLog_File_Path = ConfigurationSettings.AppSettings["logfilepath"];
> lock (FoLockObject) {
> FsLog_File_Path =
> Path.Combine(Path.GetDirectoryName(FsLog_File_Path ),
> Path.GetFileNameWithoutExtension(FsLog_File_Path) + "_" +
> DateTime.Now.ToString("yyyyMMdd") +
> Path.GetExtension(FsLog_File_Path));
> }
> }
> public static void WriteInfo(string sDescription) {
> RefreshSettings();
> StreamWriter oStream = null;
> try {
> if (File.Exists(FsLog_File_Path)) {
> oStream = File.AppendText(FsLog_File_Path);
> }
> else {
> oStream = File.CreateText(FsLog_File_Path);
> }
> oStream.AutoFlush = true;
> string sSession = "";
> if (HttpContext.Current != null) sSession =
> HttpContext.Current.Session.SessionID + " - ";
> else sSession = "";
>
> oStream.WriteLine(string.Format("{0} - {1} - {2}{3}",
> DateTime.Now.ToString("dd MMM yyy H:mm:ss"), "INFO", sSession,
> sDescription));
> }
> catch (IOException) {
> }
> finally {
> if (oStream != null) oStream.Close();
> oStream = null;
> }
> }
> }
> "George Ter-Saakov" wrote:
>> Is sLog_File_Path local or member variable?
>> What about FoLockObject?
>>
>> Unfortunately it' hard to say where is the problem you need to show us
>> full
>> class.
>>
>> George.
>>
>>
>> "Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
>> news:27A2FF7B-4565-40A5-8D95-CE197DE94166@.microsoft.com...
>> > My application uses a singleton static class for writing entries to a
>> > log
>> > file. The location and name of the log-file is read from web.config
>> > each
>> > time
>> > an entry is written, but has the current date inserted into its name.
>> > For
>> > example, the string:
>>> > c:\inetpub\wwwroot\myapp\log.txt
>>> > will be changed to:
>>> > c:\inetpub\wwwroot\myapp\log_20060216.txt
>>> > However, as we have many concurrent users on the site at once, each
>> > generating hundreds of log file entries a minute, we're finding that
>> > multiple
>> > threads are calling the same code at the same time and we're getting
>> > filename
>> > with multiple date stamps. Ie:
>>> > c:\inetpub\wwwroot\myapp\log_20060216_20060216.txt
>>> > I'm sure this is to do with the following code not being thread-safe
>> > despite
>> > the "lock" critical section statement:
>>> > string sLog_File_Path =
>> > ConfigurationManager.AppSettings["logfilepath"];
>>> > lock (FoLockObject) {
>> > sLog_File_Path = Path.Combine(Path.GetDirectoryName(sLog_File_Path) ,
>> > Path.GetFileNameWithoutExtension(sLog_File_Path) + "_" +
>> > DateTime.Now.ToString("yyyyMMdd") +
>> > Path.GetExtension(sLog_File_Path));
>> > }
>>> > Can anyone offer advice on the correct way to protect code that is
>> > vulnerable to threading issues. I'm aware of synchronization objects
>> > such
>> > as
>> > Mutex's but am unsure how to use them with static classes. A stright
>> > forward
>> > example in C# without being too clever would be very handy
>>> > Thanks
>>> > Ben
>>>
>>
>
Hi George,

I see the error of my ways and have changed it as you suggested. This was
basically a quick hack to include the date in the filename, as this wasn't
the origianl intention.

Thanks for the advice

Ben

"George Ter-Saakov" <gt-nsp@.cardone.com> wrote in message
news:OOv8TCwMGHA.3732@.TK2MSFTNGP10.phx.gbl...
> You do have a problem in your code.
> This line is not thread safe.
> FsLog_File_Path = ConfigurationSettings.AppSettings["logfilepath"];
> You are modifying the variable while some other thread could have been
> doing the code that is in lock {} section.
> So move that line inside (but read further)
> ---------------
> I am not sure why your are doing it this way. Because I do not see any
> gain in FsLog_File_Path beign global/member variable.
> I would rewrite the code to avoid any synchronization
> private static void RefreshSettings() {
> string sPath =
> ConfigurationSettings.AppSettings["logfilepath"];
> sPath = Path.Combine(Path.GetDirectoryName(sPath),
> Path.GetFileNameWithoutExtension(sPath) + "_" +
> DateTime.Now.ToString("yyyyMMdd") +
> Path.GetExtension(sPath));
> }
> }
>
> As you can see all manipulations are made to local variable so you do not
> need lock.
> --------------------
> The only place where you will need to lock is where you are opening the
> file and writing to it. Since that is not thread safe.
> And this will fail if you try to open/write into file from multiple
> threads.
> George
>
> "Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
> news:B6D5463F-61F6-41BB-B39D-7679E2587C0A@.microsoft.com...
>> Here's an abbreviated version of the full class.
>>
>> public class CLog {
>> private static string FsLog_File_Path = "";
>> private static object FoLockObject = new object();
>>
>> private static void RefreshSettings() {
>> FsLog_File_Path =
>> ConfigurationSettings.AppSettings["logfilepath"];
>>
>> lock (FoLockObject) {
>> FsLog_File_Path =
>> Path.Combine(Path.GetDirectoryName(FsLog_File_Path ),
>> Path.GetFileNameWithoutExtension(FsLog_File_Path) + "_" +
>> DateTime.Now.ToString("yyyyMMdd") +
>> Path.GetExtension(FsLog_File_Path));
>> }
>> }
>>
>> public static void WriteInfo(string sDescription) {
>> RefreshSettings();
>>
>> StreamWriter oStream = null;
>>
>> try {
>> if (File.Exists(FsLog_File_Path)) {
>> oStream = File.AppendText(FsLog_File_Path);
>> }
>> else {
>> oStream = File.CreateText(FsLog_File_Path);
>> }
>>
>> oStream.AutoFlush = true;
>>
>> string sSession = "";
>> if (HttpContext.Current != null) sSession =
>> HttpContext.Current.Session.SessionID + " - ";
>> else sSession = "";
>>
>>
>> oStream.WriteLine(string.Format("{0} - {1} - {2}{3}",
>> DateTime.Now.ToString("dd MMM yyy H:mm:ss"), "INFO", sSession,
>> sDescription));
>> }
>> catch (IOException) {
>>
>> }
>> finally {
>> if (oStream != null) oStream.Close();
>> oStream = null;
>> }
>> }
>> }
>>
>> "George Ter-Saakov" wrote:
>>
>>> Is sLog_File_Path local or member variable?
>>> What about FoLockObject?
>>>
>>> Unfortunately it' hard to say where is the problem you need to show us
>>> full
>>> class.
>>>
>>> George.
>>>
>>>
>>> "Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
>>> news:27A2FF7B-4565-40A5-8D95-CE197DE94166@.microsoft.com...
>>> > My application uses a singleton static class for writing entries to a
>>> > log
>>> > file. The location and name of the log-file is read from web.config
>>> > each
>>> > time
>>> > an entry is written, but has the current date inserted into its name.
>>> > For
>>> > example, the string:
>>>>> > c:\inetpub\wwwroot\myapp\log.txt
>>>>> > will be changed to:
>>>>> > c:\inetpub\wwwroot\myapp\log_20060216.txt
>>>>> > However, as we have many concurrent users on the site at once, each
>>> > generating hundreds of log file entries a minute, we're finding that
>>> > multiple
>>> > threads are calling the same code at the same time and we're getting
>>> > filename
>>> > with multiple date stamps. Ie:
>>>>> > c:\inetpub\wwwroot\myapp\log_20060216_20060216.txt
>>>>> > I'm sure this is to do with the following code not being thread-safe
>>> > despite
>>> > the "lock" critical section statement:
>>>>> > string sLog_File_Path =
>>> > ConfigurationManager.AppSettings["logfilepath"];
>>>>> > lock (FoLockObject) {
>>> > sLog_File_Path = Path.Combine(Path.GetDirectoryName(sLog_File_Path) ,
>>> > Path.GetFileNameWithoutExtension(sLog_File_Path) + "_" +
>>> > DateTime.Now.ToString("yyyyMMdd") +
>>> > Path.GetExtension(sLog_File_Path));
>>> > }
>>>>> > Can anyone offer advice on the correct way to protect code that is
>>> > vulnerable to threading issues. I'm aware of synchronization objects
>>> > such
>>> > as
>>> > Mutex's but am unsure how to use them with static classes. A stright
>>> > forward
>>> > example in C# without being too clever would be very handy
>>>>> > Thanks
>>>>> > Ben
>>>>>
>>>
>>>

Thread safety advice

My application uses a singleton static class for writing entries to a log
file. The location and name of the log-file is read from web.config each tim
e
an entry is written, but has the current date inserted into its name. For
example, the string:
c:\inetpub\wwwroot\myapp\log.txt
will be changed to:
c:\inetpub\wwwroot\myapp\log_20060216.txt
However, as we have many concurrent users on the site at once, each
generating hundreds of log file entries a minute, we're finding that multipl
e
threads are calling the same code at the same time and we're getting filenam
e
with multiple date stamps. Ie:
c:\inetpub\wwwroot\myapp\log_20060216_20
060216.txt
I'm sure this is to do with the following code not being thread-safe despite
the "lock" critical section statement:
string sLog_File_Path = ConfigurationManager.AppSettings["logfilepath"];
lock (FoLockObject) {
sLog_File_Path = Path.Combine(Path.GetDirectoryName(sLog_File_Path),
Path. GetFileNameWithoutExtension(sLog_File_Pa
th) + "_" +
DateTime.Now.ToString("yyyyMMdd") +
Path.GetExtension(sLog_File_Path));
}
Can anyone offer advice on the correct way to protect code that is
vulnerable to threading issues. I'm aware of synchronization objects such as
Mutex's but am unsure how to use them with static classes. A stright forward
example in C# without being too clever would be very handy
Thanks
BenIs sLog_File_Path local or member variable?
What about FoLockObject?
Unfortunately it' hard to say where is the problem you need to show us full
class.
George.
"Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
news:27A2FF7B-4565-40A5-8D95-CE197DE94166@.microsoft.com...
> My application uses a singleton static class for writing entries to a log
> file. The location and name of the log-file is read from web.config each
> time
> an entry is written, but has the current date inserted into its name. For
> example, the string:
> c:\inetpub\wwwroot\myapp\log.txt
> will be changed to:
> c:\inetpub\wwwroot\myapp\log_20060216.txt
> However, as we have many concurrent users on the site at once, each
> generating hundreds of log file entries a minute, we're finding that
> multiple
> threads are calling the same code at the same time and we're getting
> filename
> with multiple date stamps. Ie:
> c:\inetpub\wwwroot\myapp\log_20060216_20
060216.txt
> I'm sure this is to do with the following code not being thread-safe
> despite
> the "lock" critical section statement:
> string sLog_File_Path = ConfigurationManager.AppSettings["logfilepath"];
> lock (FoLockObject) {
> sLog_File_Path = Path.Combine(Path.GetDirectoryName(sLog_File_Path),
> Path. GetFileNameWithoutExtension(sLog_File_Pa
th) + "_" +
> DateTime.Now.ToString("yyyyMMdd") +
> Path.GetExtension(sLog_File_Path));
> }
> Can anyone offer advice on the correct way to protect code that is
> vulnerable to threading issues. I'm aware of synchronization objects such
> as
> Mutex's but am unsure how to use them with static classes. A stright
> forward
> example in C# without being too clever would be very handy
> Thanks
> Ben
>
Here's an abbreviated version of the full class.
public class CLog {
private static string FsLog_File_Path = "";
private static object FoLockObject = new object();
private static void RefreshSettings() {
FsLog_File_Path = ConfigurationSettings.AppSettings["logfilepath"];
lock (FoLockObject) {
FsLog_File_Path =
Path.Combine(Path.GetDirectoryName(FsLog_File_Path),
Path. GetFileNameWithoutExtension(FsLog_File_P
ath) + "_" +
DateTime.Now.ToString("yyyyMMdd") +
Path.GetExtension(FsLog_File_Path));
}
}
public static void WriteInfo(string sDescription) {
RefreshSettings();
StreamWriter oStream = null;
try {
if (File.Exists(FsLog_File_Path)) {
oStream = File.AppendText(FsLog_File_Path);
}
else {
oStream = File.CreateText(FsLog_File_Path);
}
oStream.AutoFlush = true;
string sSession = "";
if (HttpContext.Current != null) sSession =
HttpContext.Current.Session.SessionID + " - ";
else sSession = "";
oStream.WriteLine(string.Format("{0} - {1} - {2}{3}",
DateTime.Now.ToString("dd MMM yyy H:mm:ss"), "INFO", sSession,
sDescription));
}
catch (IOException) {
}
finally {
if (oStream != null) oStream.Close();
oStream = null;
}
}
}
"George Ter-Saakov" wrote:

> Is sLog_File_Path local or member variable?
> What about FoLockObject?
> Unfortunately it' hard to say where is the problem you need to show us fu
ll
> class.
> George.
>
> "Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
> news:27A2FF7B-4565-40A5-8D95-CE197DE94166@.microsoft.com...
>
>
You do have a problem in your code.
This line is not thread safe.
FsLog_File_Path = ConfigurationSettings.AppSettings["logfilepath"];
You are modifying the variable while some other thread could have been doing
the code that is in lock {} section.
So move that line inside (but read further)
---
I am not sure why your are doing it this way. Because I do not see any gain
in FsLog_File_Path beign global/member variable.
I would rewrite the code to avoid any synchronization
private static void RefreshSettings() {
string sPath =
ConfigurationSettings.AppSettings["logfilepath"];
sPath = Path.Combine(Path.GetDirectoryName(sPath),
Path.GetFileNameWithoutExtension(sPath) + "_" +
DateTime.Now.ToString("yyyyMMdd") +
Path.GetExtension(sPath));
}
}
As you can see all manipulations are made to local variable so you do not
need lock.
----
The only place where you will need to lock is where you are opening the file
and writing to it. Since that is not thread safe.
And this will fail if you try to open/write into file from multiple threads.
George
"Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
news:B6D5463F-61F6-41BB-B39D-7679E2587C0A@.microsoft.com...
> Here's an abbreviated version of the full class.
> public class CLog {
> private static string FsLog_File_Path = "";
> private static object FoLockObject = new object();
> private static void RefreshSettings() {
> FsLog_File_Path = ConfigurationSettings.AppSettings["logfilepath"];
> lock (FoLockObject) {
> FsLog_File_Path =
> Path.Combine(Path.GetDirectoryName(FsLog_File_Path),
> Path. GetFileNameWithoutExtension(FsLog_File_P
ath) + "_" +
> DateTime.Now.ToString("yyyyMMdd") +
> Path.GetExtension(FsLog_File_Path));
> }
> }
> public static void WriteInfo(string sDescription) {
> RefreshSettings();
> StreamWriter oStream = null;
> try {
> if (File.Exists(FsLog_File_Path)) {
> oStream = File.AppendText(FsLog_File_Path);
> }
> else {
> oStream = File.CreateText(FsLog_File_Path);
> }
> oStream.AutoFlush = true;
> string sSession = "";
> if (HttpContext.Current != null) sSession =
> HttpContext.Current.Session.SessionID + " - ";
> else sSession = "";
>
> oStream.WriteLine(string.Format("{0} - {1} - {2}{3}",
> DateTime.Now.ToString("dd MMM yyy H:mm:ss"), "INFO", sSession,
> sDescription));
> }
> catch (IOException) {
> }
> finally {
> if (oStream != null) oStream.Close();
> oStream = null;
> }
> }
> }
> "George Ter-Saakov" wrote:
>
Hi George,
I see the error of my ways and have changed it as you suggested. This was
basically a quick hack to include the date in the filename, as this wasn't
the origianl intention.
Thanks for the advice
Ben
"George Ter-Saakov" <gt-nsp@.cardone.com> wrote in message
news:OOv8TCwMGHA.3732@.TK2MSFTNGP10.phx.gbl...
> You do have a problem in your code.
> This line is not thread safe.
> FsLog_File_Path = ConfigurationSettings.AppSettings["logfilepath"];
> You are modifying the variable while some other thread could have been
> doing the code that is in lock {} section.
> So move that line inside (but read further)
> ---
> I am not sure why your are doing it this way. Because I do not see any
> gain in FsLog_File_Path beign global/member variable.
> I would rewrite the code to avoid any synchronization
> private static void RefreshSettings() {
> string sPath =
> ConfigurationSettings.AppSettings["logfilepath"];
> sPath = Path.Combine(Path.GetDirectoryName(sPath),
> Path.GetFileNameWithoutExtension(sPath) + "_" +
> DateTime.Now.ToString("yyyyMMdd") +
> Path.GetExtension(sPath));
> }
> }
>
> As you can see all manipulations are made to local variable so you do not
> need lock.
> ----
> The only place where you will need to lock is where you are opening the
> file and writing to it. Since that is not thread safe.
> And this will fail if you try to open/write into file from multiple
> threads.
> George
>
> "Ben Fidge" <BenFidge@.discussions.microsoft.com> wrote in message
> news:B6D5463F-61F6-41BB-B39D-7679E2587C0A@.microsoft.com...
>