|
Skynyrd wrote:
Apart from that, I would consider using System.Threading.Monitor.Enter/Exit for thread-safe objects. With the lock statement u risk throwing an exception that could deadlock ur object or what's worse, ur type if its a static method.
No it wouldn't. The lock Statement[^] is exactly doing what you suggest to do manually (see C# Language Specification: 8.12 The lock statement[^]).
Best regards
Dennis
|
|
|
|
|
eyoung70 wrote:
If I obtain a lock on an object and then spawn a new thread from within the method that obtained the lock, does the new thread have access to the locked object?
Take a look at the documentation of the Monitor.Enter() Method[^] to understand what happens when you use the lock statement[^]. In short you need to use it everywhere where threads might concurrently access an object while it might be in an inconsistent state. This happens when one thread begins to change data of the object, is interrupted and another thread accesses the (now inconsistent) object. It has nothing to do with in which thread another concurrent thread was originally created.
Best regards
Dennis
|
|
|
|
|
The rule is tremendously simple:
The lock is per thread. Is some other thread tries to lock it, it'll be blocked.
It doesn't matter which object or which method. All that matters is wich thread.
HTH.
Yes, even I am blogging now!
|
|
|
|
|
If I have a single WebBrowser control (either the managed wrapper in 2.0 or the ActiveX instance), is there anyway I can force it to draw to the screen multiple times without creating multiple instances of the control? Basically what I want to do is:
-------------------
<draw some html in here>
-------------------
<draw other html here>
-------------------
and so on. I know I can do this with the RichTextBox via P/Invoke (MSDN article on that here[^]), but that same P/Invoke trick doesn't seem to work on the WebBrowser control.
Any remotely useful information on my blog will be removed immediately. There are 10 kinds of people in the world. Those who have heard of the ubiquitous, overused, worn-out-like-an-old-shoe binary "joke" and those who haven't.
Judah Himango
|
|
|
|
|
Hello all
I made a desktop application the useres enter data in text boxes but when the user enter this Char " ' " make confilect with with SQL Statement
eg.
Select * from Names where Name='"+Name+"'
if Name contain any ' it will make SQL statment error
pleae help
Hay![Frown | :(](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_frown.gif)
|
|
|
|
|
Someone once said in this forum "Sql string concatenation is sooooo 1990s" Do not use string concating for sql statements, that opens you up to Sql injection attacts. Instead, use parameterized queries, which will also take care of your char apostrophe problem:
SqlCommand command = new SqlCommand("Select * from Names where Name = @Name");
command.Parameters.Add("@Name", myNameVariable);
Any remotely useful information on my blog will be removed immediately. There are 10 kinds of people in the world. Those who have heard of the ubiquitous, overused, worn-out-like-an-old-shoe binary "joke" and those who haven't.
Judah Himango
|
|
|
|
|
Hi, my name is:
';DELETE FROM Names;--
can you enter my name in the name paramand test it works for me please.*
* dont do this really, just make sure you use parameterized queries for important data
|
|
|
|
|
|
Hi all,
I am having a doubt, whether we can use C# for programming graphics environments instead of using OpenGL. I am not familiar with OpenGL, I have tried a couple of times to learn it, but not interested. But rather i am more interested in learning C#, if we can develop graphics environments in C#. I want to develop some simple applications like creating an environment(Ex: room) with objects like sphere, cube, pyramid etc...)
The main question is can we use C# for developing the applications that we develop using OpenGL?
Thanks in advance,
Suman.
Suman
|
|
|
|
|
A moot question considering your comparing apples and oranges. C# is a general purpose language for writing applications while OpenGL is an API Library, not a language.
You can use C# to write a graphics environment and have it call OpenGL functions to actually draw the visuals on screen.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
yep thts wht i am asking/looking for, can't we draw visuals on screen using C# alone without OpenGL?
Suman.
|
|
|
|
|
C# doesn't have any drawing functions. If your talking about drawing without using a non-Microsoft API, then your talking about GDI+. In C#, or any other language targeting the .NET Framework, the basic functionality is encapsulated by the System.Drawing namespace.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
Why does this code raise an exception?
<br />
OleDbConnection m_adoConn;<br />
OleDbCommand cmdPrj = new OleDbCommand("SELECT * FROM project", m_adoConn);<br />
OleDbDataReader readerPrj = cmdPrj.ExecuteReader();<br />
while(readerPrj.Read())<br />
{<br />
OleDbCommand cmdUp = new OleDbCommand("UPDATE project SET PrjName=\"TESTE\"", m_adoConn);<br />
}<br />
readerPrj.Close();<br />
The exception message is: "There is already an open DataReader associated with this Connection which must be closed first"
My main question is "WHY?" - is there anyway to keep the datareader opened, so i can change or insert some data to the current database (where the connection is pointing to)?
Thank u very much,
Dirso
|
|
|
|
|
The exception is quite clear: you can only have one DataReader open per connection. And how would keeping the DataReader open help you update the records? This isn't ADO - it's ADO.NET and it does work a little differently. The OleDbCommand.ExecuteNonQuery is how you update data, or you could use a DataSet and a DataAdapter derivative (in your case, using an OleDbDataAdapter ) to fill and update data. A DataSet is a disconnected recordset that contains tables with column definitions, change tracking, serialization support (in .NET 1.x, only to XML; in .NET 2.0, to XML and binary), and even referential integrity.
Read in the .NET Framework SDK about the DataSet class and the DataAdapter class, both of which include examples in the class and their members' documentation topics.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
A DataReader needs exclusive access to its connection and will not be able to share it with anything else while its open. If u need to execute some other query while a reader is active you will have to create a new connection.
|
|
|
|
|
Hello,
I have a datagrid with books, when the book is overdue i want it to change the text to Red. A for has been used to go through each row (works fine). But when it comes to a book that is overdue, l want it to change the text to red. I have tired using the code below, but does not work.
if ( dateDue < todaysDate )<br />
{<br />
grdBookOnLoan.Select(i);
grdBookOnLoan.ForeColor = Color.Red;<br />
grdBookOnLoan.UnSelect(i);<br />
}
Thanks in advance,
Steve
|
|
|
|
|
You might try adding an extra hidden column into the datagrid, a boolean that indicates whether the book is overdue. Then use the "OnPreRender" in your html markup to execute a method that checks if the book is overdue and changes the forecolor of the object if it is.
code works something like this
<br />
<asp:Label id="myLabel" runat="server" OnPreRender="CheckOverdue"/ ><br />
<br />
In your codebehind
<br />
public void CheckOverdue(object sender, EventArgs e)<br />
{<br />
System.Web.UI.Controls.Label lbl, lblIsOverdue;<br />
lbl = (System.Web.UI.Controls.Label)sender;<br />
lblIsOverdue = (System.Web.UI.Controls.Label)e.Item.Items.FindControl("lblIsOverdue");<br />
<br />
if(lblIsOverdue.Text == "true")<br />
{<br />
lbl.ForeColor = Color.Red;<br />
}<br />
}<br />
And that should do it. Please note that this code works on a label by label basis, not a row by row. I'm not sure what this type of method does to scalability or load times (never used it in an enterprise app). So if this is for a large app, you might want to load test with and without.
Hope that helps.
Tojamismis
A mind never grows without mistakes and questions.
|
|
|
|
|
hi all ,
I store a data in sql with sqlmoney type but when i try to divid sqlmoney value it give me error that it cant apply this operans with sqlmoney
SqlMoney salary;
salary/2;
please help
hay![Frown | :(](https://www.codeproject.com/script/Forums/Images/smiley_frown.gif)
|
|
|
|
|
The second operand has to be a SqlMoney structure too. Take a look at the documentation for more information regarding division of SqlMoney.
www.troschuetz.de
|
|
|
|
|
Ok, i'm trying the DirectX.Capture Class Library and it itsn't working.
i have a problem here because hr=1 after this
hr = enumDev.CreateClassEnumerator( ref category, out enumMon, 0 );
so it doesn't enter this "if"
if( hr != 0 )
throw new NotSupportedException( "No devices of the category" );
can anybody tell me what this means
Thanks,
|
|
|
|
|
Hi.
I want to know if there is any material availbale in the internet regarding soap extensions. I have a project where i have to construct the soap message by myself. so it would be very useful for me, if somebody can guide me to that.
Thanks
|
|
|
|
|
All,
I'm new to C#, coming from a C++ background. Is it possible to have a single namespace span multiple files and if so how?
Thanks,
Bill Weiss
|
|
|
|
|
Yes, it is.
File 1 (MyClass1.cs):
namespace MyNamespace
{
class MyClass1
{
}
}
File 2 (MyClass2.cs):
namespace MyNamespace
{
class MyClass2
{
}
}
www.troschuetz.de
|
|
|
|
|
Hi, guys and girls
How can I change the font of text displayed in a MessageBox?
Thanks
vigorous
|
|
|
|
|
AFAIK you cannot.
But it should be pretty simple to write your own MessageBox, which provides this feature.
www.troschuetz.de
|
|
|
|