.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

lock an object to multithreads by using lock inside the object's class..

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :Windows Application


I have a main program that holds static object.

The program launches multi-threads. all of this threads access the same static objec.

Problem is that I don't wish to allow access the same object at the same time for multuiple threads.

I wish to use LOCK inside the object....inside the class....and not write LOCK in the threads. this is frustrating.

is it possible?

How do I do that?

View Complete Post

More Related Resource Links

CLR Inside Out: Large Object Heap Uncovered


This month CLR Inside Out reveals the secrets behind the Large Object Heap-what's there, when it's released, how the garbage collector handles the objects there.

Maoni Stephens

MSDN Magazine June 2008

CLR Inside Out: Managing Object Lifetime


Although the .NET Framework provides a managed execution environment, it is important to consider object lifetime management and write code that uses and releases resources correctly. The CLR team shows you how.

Tim Fischer

MSDN Magazine November 2007

Building a Custom Data Grid: Performing Ad Hoc Web Reporting with a VBScript 5.0 Class Object


A flexible, customizable grid for displaying data is a useful tool for ASP developers. It allows Web visitors to customize their view of your data. This article takes the data grid presented in "Ad Hoc Web Reporting with ADO 2.0" by John Papa and Charles Caison (MIND, December 1998) and adds handy features such as a finds feature that supports multiple finds and a mode for adding and editing records. This version also improves response time by allowing asynchronous record download and it componentizes the code so it can be used as a standalone VBScript class object that can be reused in other pages.

Randall Kindig

MSDN Magazine July 2000

send data in class object from one page to another using session


hello everybody

now i hav stored all data like user name, data fatched from database of that user

and i stored that data and user name such as:

string strUserName="user name"

dataset ds =new dataset();// data of that user

now i wan yo send d whole data from my login page to user profile page

can anybody help me for that...................

and plz tell me that how much is this way is benifitial to send data from one page to another page

plz........kindly waiting for positive rply

Cannot access Label inside Repeater - "Object reference not set..."


I have a button on a page with a Repeater and an ObjectDataSource. To give credit where credit is due, the Repeater's paging functionality is courtesy of ScottGu. (However, I'm using ASP.NET 4.0 and SQL Server 2008, as opposed to ASP.NET 2.0 and SQL Server 2005.)

Anyway, in the button's click event, I need to access the Text property of a Label that's inside the Repeater because it's used as an input parameter in a stored procedure. I'm getting a NullReferenceException when trying to access the Label's Text property. I have researched this error and have tried a few different solutions (involving FindControl and the Repeater's ItemDataBound event), but I haven't been able to get it to work. Any suggestions, in VB or C#, would be greatly appreciated. The code is below.


<asp:Repeater ID="rptText" runat="server" DataSourceID="tbsDataSource">
<table width="100%" cellspacing="1">
<%-- some rows removed for brevity --%>

How to: Serialize Hashtable contained inside another object that is serialized as an array of object

Update:  I've added the entire program in a single block of C# text near the end of these posts that can be placed into a C# Program.cs file of a console project.   I have a class called MyHashtable that inherits from Hashtable and implements IXmlSerializable.  MyHashtable is contained inside another object called MyObject and I need to xml serialize an array of MyObject[].  Whenever I xml deserialize, the hashtable is deserialized, but only 1 of MyObjects from the MyObject[] array is deserialized.  The ReadXml uses "while (reader.NodeType != XmlNodeType.EndElement)" so I don't think the reader is consuming all of the xml internally.   Does anyone know why this is happening?  Thanks.    

Calling a method with a class object as parameter data type.

   [WebMethod]    public string GetInfo(Customer inCust)    {        // Code in here    } I have a web service that resides on a remote server. I want to call a public method of theweb service named  "GetInfo". The method is shown above. The web service method expects a class object oftype "Customer". What I did to create a Customer object was to define in my asp.net project my own class named "Customer" which is exactlythe same as the class that belongs to the web service project on the remote server. I then created an instance of Customerand tried to call the web service passing in an object of type customer : my.Service ws = new my.Service(); // Get web service connectionCustomer aCustomer = new Customer();aCustomer.Initialize();ws.GetInfo(aCustomer) // call web service passing in a Customer object The problem is that the compiler gives me the following error: Value of type '_Default.Customer' cannot be converted to 'ws.Class1'. Here Default is refering to my Default.aspx.cs code. Why is this? Do I need to Cast my "aCustomer" class object to a type ofws.Customer ? How do I do that?

Cannot send List inside of Dictionary

List<string> receivers = new List<string>(); foreach (object item in listBoxControl1.SelectedItems) receivers.Add((string)item); Dictionary<string, object> inArgs = new Dictionary<string, object>(); inArgs.Add("Receivers", receivers); inArgs.Add("Sender", client.name); inArgs.Add("Message", memoEdit2.Text); inArgs.Add("IsGuaranteedDelivery", true); inArgs.Add("DataType", TransmitToClientDataType.ChatMessage); if (service != null) service.AddTask("orion_send", inArgs); There is an error with serialization at last string because List<string> object. I tryed to send List<T> object via WCF, it's succesfull. But why there are problems with List<T> included to Dictionary?

Using extensions with Object Class and Page in WPF

I don't usually ask a question without trying it first, but hey, why not.  Searching for this one is not exactly easy. I am wondering if I can use extensions with Object and if they (the variables) will subsequently be available for use in a Page partial class generated for WPF?  By this I mean in the same project and assembly. BTW, I won't be offended by posts pointing out why not to do this with Object.  The why in this case is something as basic as having one base class that contain: bYes = True; bNo = False; Now of course, having a base class is not going to work with something like Page... There may be much better ways to this, what I do not want is syntax MyBaseInstance.bYes and MyBaseInstance.bNo in MyPageInstance and bYes or bNo everywhere else.  Any advice? Regards,  Dave Horsman

Unable to Create Object Variable for Linq Data Class


For some unknown reason I suddenly am unable to create an object variable for a Linq Data Class. If I create a new project and try the process again with the same database everything works as advertized.

The code I am using is Dim db As New RoggDataContext  which gives me an error on the object variable "db": Overload resolution failed because no accessibility 'NEW'  accepts this number of arguments.

I have looked inside every file in the Web Project like the web config to check the connection string, gobal, and designer.vb looking for any errors whit no JOY.  I also tried to create a new form and code behind with a button and received the same error.

This is mind blowing because as I already stated, I can create a new Web Site and the problem goes away.

Any help is appreciated!



How to recognise obsolate object from isolated storage whose class has been changed?

<!-- [if gte mso 10]> <mce:style>


Our company is building a word add-in (document-level add-in) with visual studio 2008, word 2007 and VSTO 3.0 sp1

There is one issue that causes us a headache. It is related to obsolete objects in isolated storage.

In Word add-in we serialize object and save it to isolated storage. Later we can load that object from isolated storage and use it in our application.

The problem occurs in following scenario:

-We are working in Word add-in and save one serialized object to isolated storage

-Turn of Word add-in and change code of the class whose instance we have saved in isolated storage

-Work in word add-in again and load and deserialize object from isolated storage. This object is of obsolete class and code usually breaks here or later in code when we are trying to access changed content.

If this scenario happens, we will clear obsolete object from isolated storage. Issue is how to recognize that object’s class is changed?

We tried to recognize changes in the following ways:

·       &

how to create class and acess member using object

hi i am a new user to C# .net can any body help me to write a new class in c# AND HOW TO ACESS methods and members using its object thnks in advance

page inside update panel doesn't refresh the session object after postback of any control



I have many controls like dropdown, radiobuttonlist, etc on my page and I put all these controls inside the update panel so that the page doesn't look to be posting back when something is selected. Now the working on the page is very smooth. But the session object isn't getting refreshed even if I postback to the server and as a result even if the users are working on the page they are being sent to the login screen after 20 mins.

Is there anyway where I could put all the controls in update panel and still refresh the session after any postback(dropdown selection)

Any help is greatly appreciated.

Thanks in advance

How to update value directly in class Object using Linq



I have a class object which is basically kind of hierarchy and looks like this when I convert that to XML.


  	<SKU>SKU 1</SKU> 
	<ConfigurationStatus>Not Configurable</ConfigurationStatus> 
  			<SKU>SKU 2</SKU> 
  			<ConfigurationStatus>Not Configurable</ConfigurationStatus> 
  					<SKU>SKU 3</SKU> 
		  			<ConfigurationStatus>Not Configurable</ConfigurationStatus> 



So you can see that I have "objectComponent" which is kind of hierarchy and that hierarchy can be upto any level.

Now I need to update <quantity> value where <sk

how to persist a class object when page PostBack


i have created a user control UserControl.ascx, in Code behind file of UserControl.ascx i have created an object of a class MyClass.cs,
if(!Page.IsPostback) {
objMyClass= new MyClass();
but when i click on button of UserControl.ascx page and try to access objMyClass object then it set as null, so how to persist MyClass object when page PostBack, i wanted to keep object persist till the user access the page, when user goes out of this page then object should distroy?

To keep the object persist, i have used ViewState

So i have made MyClass Serializable and
i have used ViewState to keep my objet persist, but it give the error
like : UserControl is not marked as serializable.

so i have made my UserControl as Serializable, but the problem is still coming.

One more thing is that MyClass is also resposnsible to create some other class object also.

Can any one suggest me correct solution?

Problem i am getting when i try to PersisObject On UserControl

[SerializationException: Type 'ASP.common_grid_UserControl_ascx' in Assembly 'App_Web_44142fbl, Version=, Culture=neutral, PublicKeyToken=null' is not marked as serializable.] System.Runtime.Serialization.FormatterServices.InternalGetSeri

Interface object Versus Class Object


Asslam o Alaikum

namespace Interface
    interface IMyInterface
        void Start();    
        void Stop();

    class Program : IMyInterface
        void IMyInterface.Start()
            Console.WriteLine("\n Void Start Method Implement");
        void IMyInterface.Stop()
            Console.WriteLine("\n Void Stop Method Implement");
        static void Main(string[] args)
            IMyInterface iMyInterface = new Program();

1. IMyInterface iMyInterface = new IMyInterface(); // if i create the object of interface i get Error
2. Program iMyInterface = new Program(); // if i create the object of program i can't get the property of Interfaces i.e. Start(); stop();
3. IMyInterface iMyInterface = new Program(); // This will work fine

i want know the difference about 3 points can any body claer it ..


How to Bind ExpressionTextBox to my class object in ActivityDesigner?



I am just learning WF so this may be a easy question to answer.

I have a custom code activity, AddJobToQueue that takes as input arguments a MessageQueue and a JobTicket. JobTicket is my custom class from a separate library (added as a Reference).

In trying to create an custom activity designer for my activity, I have hit a snag. My activity designer uses two ExpressionTextBoxes for the two input arguments. I was able to get the binding correct for the MessageQueue, but I cannot determine how to get the binding for my custom class.

My current XAML is this:

<sap:ActivityDesigner x:Class="QueueActivityLibrary.AddJobToQueueDesigner"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend