.net - Static Property And Lock Usage

Mar 27, 2009

Is this code correct or is there any possibility of some random threading deadlocks etc?

Is it a good idea to use static properties and locking together? Or is static property thread-safe anyway?

Private Shared _CompiledRegExes As List(Of Regex)
Private Shared Regexes() As String = {"test1.Regex", "test2.Regex"}
Private Shared RegExSetupLock As New Object

[Code]....

If it's not obvious code is compiling regexes and storing in a List(Of Regex) so they can run faster. And it's shared so every instance of class can get benefit out of it.

View 6 Replies


ADVERTISEMENT

Should Always Lock Static Methods?

Nov 3, 2011

In the following example GetList returns an instance of a static (shared) variable. That one needs locking in order to be thread-safe.But what about DoSomething which doesn't use any static variables outside the method? Does it need locking too?I'd like to clarify that in this particular case I expect DoSomething to always print 0-100 in sequence (i.e. no 0123745...) regardless of number of calling threads. Or, in general, that different threads don't affect each other's variables (printing to console is only an example). The language in the following example is VB.NET.[code]

View 3 Replies

Possible To Have A Shared/Static Dependency Property?

May 25, 2010

[using VB.NET, but I can easily read C# code in responses]I have a class called QuestionClipboard with ALL shared methods/properties. I previously had a QuesitonClipboard.doesClipboardHaveContent function that returned true/false if there was a Object on my 'clipboard'.I'd prefer to implement a Dependency Property so I can allow this true/false value to participate in data binding.The "GetValue(dp as DependencyProperty)" method requires an object instance, which would mean that my Property CAN'T be shared!Here is what the code would look like in my perfect world... Of course, the word "Shared" before the property declaration renders this code useless.

Private Shared clipboardHasContentPropertyKey As DependencyPropertyKey = DependencyProperty.RegisterReadOnly("clipboardHasContent", GetType(Boolean), GetType(QuestionClipboard), _

[code]....

View 1 Replies

Use Of Static Local Variables In Lazy Loading Property

Sep 19, 2011

I just recently learned about the uses of static local variables in VB.NET and wondered about it's potential use in lazy loading properties.

Consider the following example code.

Public Class Foo
Implements IFoo
End Class

[Code].....

As far as i can see, this has a few advantages over the usual implementation, primary your inability to access the variable outside of the property, as well as not having to use an additional variable.

My question to you is: Which of those is the "right" way to do it? I know that static variables have additional overhead, but is it bad enough to create, in my personal opinion, unclearer code that can be misused easier? How much performance do you lose compared to the "traditional" method? How does it matter for small classes compared to huge factories?

View 2 Replies

Usage Of Property - Incorporate Classes To Work Style?

Mar 22, 2010

So far I only see Property being used as a means of validation in my learning material. I think maybe that's because it might be an easy way to demonstrate its usage. But isn't validation done with some kind of vb validation or on change event? Or do we use property in those events? I want to duplicate those techniques where applicable so I can get better and be more on the same page as the more advanced programmers. I'm working on incorporating classes to my work style. I see that I'm doing lots of repetitive type coding in projects that I want to put in a class. So Property keeps popping up during the learning curve. But I don't want to code Property in a mis-used way just for the sake of using it.

View 3 Replies

Class Property Usage - Unable To Retrieve A Variable From On Class

Nov 14, 2009

I have three class files, accounts.vb and transactions.vb in addition to my form.vb. I am unable to retrieve a member variable from on class from inside the other. When the combobox index changes, the program loads the correct account (checking or saving) from two different sequential files. I don't think I have the calcBalance procedure in the correct class file. And that is what I am having trouble with. Accessing it to display it. [Code]

View 1 Replies

Get The Current Number Of Usage Days, Unique Usage Days, Etc In An Evaluation License Using CryptoLicensing Generator?

Jan 25, 2010

Get the current number of usage days, unique usage days, etc in an evaluation license using CryptoLicensing Generator.

View 1 Replies

.net - 'Property' Cannot Implement 'Property' Because There Is No Matching Property On Interface 'IName'?

Dec 9, 2011

I'm having some very weird issues with interfaces right now.

I have a very simple setup. In one of my class, I have a Property implementing a Property from an Interface.

In my class it's like:

Private _oForm As IForm
Public Property Form As IForm Implements IContainer.Form
Set(value As IForm)

[Code]...

I have like dozens of interfaces like this working throughout my project and I can't believe this simple one can't work!

View 1 Replies

Static Constructor In .Net?

Feb 9, 2010

I am rewriting a C# class in VB. The C# class has a static constructor in it:

static Class()
{
...
}

which, through the Call Stack, I found is called by the main window's InitializeComponent() method.Everywhere I've looked has told me that the corresponding static constructor in VB is just:Shared Sub New()

but this method is never invoked. Am I creating my VB static constructor right? Is it likely something else that has nothing to do with my static constructor?

View 1 Replies

Static Variable In Asp.net?

Dec 15, 2011

I am writing a code for a webapplication in vb.net. I am using a shared variable in the vb code.

Consider the static variable value is 3 for a user who hits the web application. Again when another user hits the same web application, whether the static variable will be 3 again or whether he will have a separate value for static variable for his session?

View 1 Replies

How To Get CPU Usage

Apr 28, 2009

How do I get the cpu usage percentage to display in the label on a form?

View 4 Replies

.net - LINQ And Static ObservableCollection?

Nov 7, 2011

This will probably be a basic questions for the LINQ & architecture experts however I am failing to understand a problem i've encounted when trying to update a 'Static ObservableCollection.

Me.Grid1.ItemsSource = ContactList Me.Grid2.ItemsSource = From s In ContactList Where s.ContactTypes.Any(Function(t) t.ContactTypeName = "Christmas List")

If I add a new Contact with the ContactType "Christmas List" to the ContactList ObservableCollection, Grid1 reflects the additional Contact however Grid2 does not reflect the change unless I rebind.

Anyway to Reflect the change in Grid2 to show the new Contact with the queried ContactType

View 2 Replies

.net - Static DateTime For Testing?

Dec 11, 2009

We have a DateTime Service that pulls the Database date down when we need to use a Date. Now, If I want to run a test using "Todays" Date using FitNesse, What would be the easiest way of creating a way to have (OurService).CurrentDate be static? We have a control that ads Days,Years, or Months to the current date.. and I would like to be able to test this.

View 1 Replies

Adding A Static Crypt Key?

Jul 15, 2011

I am currently using Visual Basics 2010 (Ultimate), and I am trying to modify a free-project listed here:I want the above project to use these hard-coded values below:Key= "087CF262E0E856B8F911B369EE027CF9330F6288343651B1198379A9813BC8C4"
IV = "11D2A07242B79C752E6B53CDD14792C9"So basically i want to encrypt AND decrypt with the above keys.

View 8 Replies

C# - Shared / Static Variable Should Be Nothing?

Jan 6, 2011

I have the following code:
Public Class TestClass
Public Sub Main()
If theGlobal IsNot Nothing Then Throw New Exception("What gives!")
End Sub
Private Shared theGlobal As Object = Nothing
[Code] .....
Why is theGlobal object NOT Nothing?

View 2 Replies

C# Vb: When They Say Static Classes Should Not Have State?

Apr 23, 2011

when they say static classes should not have state/side effects does that mean:

static void F(Human h)
{
h.Name = "asd";

[code].....

View 3 Replies

Limit Static Integer?

Apr 28, 2011

how to limit static integre.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Static a As Integer[code]......

View 2 Replies

Static Gmaps In Winform?

Oct 2, 2011

Im trying to load a google static map in a winform. I found a control online that would helpme but i cant get it working. i got the control from Here. i was not able to drag on the control on to the form like others. i have also email the dev of the control but have not heard back yet.

[Code]...

View 1 Replies

Static Variables On A Web Garden?

Aug 17, 2010

Do vb.net static variables work on an IIS web garden?

View 1 Replies

VB Static Date Updates?

Oct 11, 2010

I have an excel sheet developed by a vendor that I'm stuck with the current functionality as a short term solution. The users workflow have them pull 4 separate sets of data which they are copying and pasting into a different spreadsheet where they append the data to previous days' pricing for trend analysis. That macro is built looking for the first blank row in column A, simple enough.

However, they then add the current day's date to this other spreadsheet as an additional column to do that trending. I found a nice link to a site that mentioned I could do this logic by adding code by right clicking the sheet name and selecting 'View Code'. I then entered the following logic that states if column A is populated, populate Column T with today's date statically (Today and Now don't work because I need it to stay at that date when it is refreshed). My issue is that this works great if I enter test data into cell A and hit enter. However it is not populating the date if a copy and paste is executed into the column A. Is there something I'm missing or a recommendation to have this work with copy/paste?

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A2:A15000")) Is Nothing Then

[code].....

View 2 Replies

What Is Equivalent Of A Static Class

Nov 30, 2007

what is the Equivalent of a Static class in VB.Net. Is it Modules?And When i used one of the C# to VB.Net conversion tools then the code "Public Static class Class1 " was converted to "Public NotInheritable Class Class1"

View 1 Replies

Why Is Static Method Not Visible

Sep 14, 2011

I have a C# method in my datatier that I am trying to convert to VB.Net. I converted it to VB.Net but when I bring up the datatier class the method is not showing. It has been a long time since i have used VB.Net and forgot alot of things [code]I believe it has to do with the declaration, which i have as:Public Static Function UserActInfo(ByVal _eno As String) As useraccount..

View 1 Replies

A To Z Usage Of Interfaces In .NET?

Dec 30, 2011

In this discussion let us discuss every usage of interfaces in .NET. Any real time examples and difficulties in using interfaces can also be discussed here.

View 6 Replies

Add A Usage Timer?

Oct 4, 2009

How would i moniter how long a user uses my program and when it reaches a hour it will close the program, but then the user will have to wait 24 hours before they can gain accesss to the form again perhaps open a msgbox that shows how long is left till it can be used I like.. [code]...

View 2 Replies

Get Cpu Usage Of Processes?

Jun 7, 2011

im making a task manager and want to get cpu usage of a process this is how my code looks now

For Each proc As System.Diagnostics.Process In pList
Dim lstStuff As ListViewItem = New ListViewItem()
lstStuff.Text = proc.Id.ToString

[code]....

everything works but the cpu part it returns values over 100%?

View 3 Replies

Getting CPU Usage In VB2010?

Aug 2, 2010

im using visual basic 2010 express and im wanting to know how i can display the CPU usage (over all CPU usage like you would find on the task manager), the RAM usage, the temperature, and the frames per second all in separate list boxes.I have searched around on the internet for a long time looking for the code's to do this, none seem to be compatible with the 2010 express version.

View 12 Replies

Getting The Declaration And Usage?

Aug 6, 2009

I was told to use this to specify a folder that I want my node to go to.

(Declaration)
<ComVisibleAttribute(True)>
Public Enumeration SpecialFolder
(Usage)
Dim instance As Environment.SpecialFolder

View 2 Replies

VS 2008 Usage Of UDP In .net?

Sep 24, 2009

I was thinking in doing some voice chat in my application which requires the use of UDP.

If you know any useful articles or can give me a boost I will be very glad and obliged.

View 15 Replies

C# - Assign Value To Readonly Static Field?

Nov 17, 2011

I have a field which is static and readonly. The requirement is that the value should be allocated to the field at the login time and after that it should be readonly. How can i achieve this ?

public static class Constant
{
public static readonly string name;
}

View 5 Replies

C# - Performance Of Static Properties/functions?

Apr 5, 2011

is there a difference in performance when making properties static/shared that were instance properties before, maybe any locking mechanisms?There is a heavily used object in HttpCache which was accessible through a property in a page-instance(Service.aspx). Now i wonder if it would be better to make it static because the HttpCache is shared across the application anyway.

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved