.net - Using .Contains Method With Cached Hashset

Jul 26, 2011

I know that the .Contains method on a hashset is fast. My question is what is the best method for getting the hashset data before repetitively using the .Contains method?

I can think of 2 options. Both of these examples would be called in a loop of undetermined length.

1) Call the method that returns the cached hashset directly and use the .Contains method.

IF (GetHashSetMethod.Contains("TESTVALUE") THEN BLAH, BLAH, BLAH...

2) Create a new hashset outside of the loop and load the cached hashset data into it so the method that returns the hashset is only called once, then use the .Contains method.

DIM HashTest AS HASHSET(OF String) = GetHashSetMethod

Then in loop:

if (HashTest.Contains("TESTVALUE") THEN BLAH, BLAH, BLAH...

I have been using method 1. Should I even think about switching to method 2? Is there a 3rd option I haven't even thought of? Does it even matter because the data is cached to begin with?

View 2 Replies


ADVERTISEMENT

Differences Between A HashSet(of T) And A List(of T)

Oct 10, 2011

What are the differences between a HashSet(of T) and a list(of T). I recently discovered HashSet and it seems to be substantially faster and uses much less memory than a list, so why use a list at all ?

View 5 Replies

Hashset For Contains With List(of String) .net?

Sep 20, 2010

Would the following:

Dim stringlist As List(Of String)
Dim stringlisthas = stringlist.Contains("thing1")
be any slower than
Dim stringlist As List(Of String)
Dim stringlisthash As New HashSet(Of String)(stringlist)
Dim stringlisthas = stringlisthash.Contains("thing1")

Is a hashset needed for contains?

View 1 Replies

Using A Custom Class In HashSet

May 30, 2010

I created a custom class which just stores 3 byte values, (R G B to be exact), which constantly change. So my idea was to store that class in a HashSet, then create a new instance of the class (with different byte values) then add that to the HashSet. There can be duplicates, which is why I decided to use a HashSet, which will ignore an item if it's allready been added. Doing this on a List would be too slow.But I've ran into a problem. Adding a custom class to hashset seems to only allow 1 to be added. I assume this is because its hashing the class object while ignoring the data (byte rgb values) it contains? Is there a way around this? It's possible to convert the RGB to Color and just use that in the HashSet, but conversion is a bit too slow.

View 2 Replies

Display A HashSet As Either A Collection Or An Array In The PropertyGrid?

Dec 21, 2011

How do I Display A HashSet As Either A Collection or an Array in the PropertyGrid.I wish there was some Attribute that allow me to display IEnumerable as an Array...but so far my attempts to do that have failed!My current solution is unacceptable in the new places I want to use it in

[Code]...

View 3 Replies

Generate Random Images Without Repeat Using Hashset?

Jan 10, 2010

I am trying to generate random images from access database using hashset as it is said to be unique and there won't be any repeated images appearing. But, it doesn't seem to work. ow can i get it to work? By the way, i am very new to the concept of hashset.

Private Function GetImageFromByteArray(ByVal picData As Byte()) As Image
If picData Is Nothing Then
Return Nothing

[code].....

View 1 Replies

How To Generate Random Images From Access Database Using Hashset?

Jun 22, 2010

I am trying to generate random images from access database using hashset as it is said to be unique and there won't be any repeated images appearing. But, it doesn't seem to work.

How can i get it to work? By the way, i am very new to the concept of hashset.
Private Function GetImageFromByteArray(ByVal picData As Byte()) As Image
If picData Is Nothing Then
Return Nothing
End If

' is this is an embedded object?
Dim bmData As Integer = If((picData(0) = 21 AndAlso picData(1) = 28), 78, 0)

' load the picture
Dim img As Image = Nothing
Try
Dim ms As New MemoryStream(picData, bmData, picData.Length - bmData)
img = Image.FromStream(ms)
Catch
End Try

' return what we got
Return img

End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Panel1.Visible = False
Panel2.Hide()


Dim conn As New OleDbConnection
Dim DA As OleDbDataAdapter
Dim DS As New DataSet


conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;User Id=admin;Password=;"

DA = New OleDbDataAdapter("Select Empty, EmptyName, Target, TargetName from PicturesDisplayed", conn)
DA.Fill(DS)

Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage


Dim oledbconnection As OleDbConnection
oledbconnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsAdministratorDesktopdb1.mdb;Jet OLEDB:System Database=system.mdw;")

oledbconnection.Open()
Dim command As OleDbCommand
command = New OleDbCommand("select count (*) from PicturesDisplayed", oledbconnection)
Dim count As Integer
count = command.ExecuteScalar()
oledbconnection.Close()


Dim randomImage As New HashSet(Of Integer)
' Create a integer and new Random object
Dim intPic As Integer
Dim rand As New Random

'Pick a random number between 0 and the number of images in database
intPic = rand.Next(0, count)
randomImage.Add(intPic)

PictureBox1.Height = 256
PictureBox1.Width = 256

PictureBox2.Height = 256
PictureBox2.Width = 256


Dim pic1x As Integer = _
(Me.ClientSize.Width - PictureBox1.Width) 2
Dim pic1y As Integer = _
(Me.ClientSize.Height - PictureBox1.Height) 2
PictureBox1.Location = New Point(pic1x, pic1y)


Dim pic2x As Integer = _
(Me.ClientSize.Width - PictureBox2.Width) 2
Dim pic2y As Integer = _
(Me.ClientSize.Height - PictureBox2.Height) 2
PictureBox2.Location = New Point(pic2x, pic2y)

' Now set the picturebox image equal to the image chosen from the array randomly using the random
PictureBox1.Image = GetImageFromByteArray(DS.Tables(0).Rows.Item(intPic).Item(0))
PictureBox1.Visible = True
PictureBox2.Image = GetImageFromByteArray(DS.Tables(0).Rows.Item(intPic).Item(2))
PictureBox2.Visible = False


If (randomImage.Count = count) Then
Me.Close()
End If

End Sub

View 1 Replies

IDE :: Cached Items In Toolbox?

Jun 10, 2010

I have a rather large project that several developers access via MS SourceSafe. The issue at hand is the ToolBox lists many, thirty plus, items that start Cached.(the name that follows Cached is the name of a class or Cyrstal Report in the project. There are also many items listed, they have the same "gear" icon, without the word Cached prefix on the class name.

My question is, how can I get these items out of the ToolBox so they never come back?

View 3 Replies

Is Size Of Lists Cached In Some Way

Jan 17, 2010

Is the size of Lists cached in some way (calculated the first time you call it, and then retained untill some change is made to it), or does it get calculated every time you call the Count property? Same question for arrays.

View 11 Replies

Linq2SQL Counts Getting Cached?

Sep 23, 2009

I've got a very simple data structure. I'm using SQLExpress with Linq2SQL and vb.net

**ParentClass**
parentId
name

[code].....

View 1 Replies

Reading Cached Images?

Jan 31, 2012

I've been working on my own web browser for a few years now using the webbrowser control in VB.Net.The following routine allows me to pull images on a web page that are stored in the cache:

Private Function GetCachedURLPath(ByVal lpszUrl
As String)
As Boolean

[code]....

This routine has worked well for me, but there are some pages where it is unable to pull the image from the cache. What discovered is that when a web page host images on a different server than the page hosting server, the images get stored in the cache with the address from the image server instead of the src address listed in the IMG tag. Given that I am using the URL from the src in the IMG tag, the routine fails to provide a return path.In most instances reloading the page puts the image into the cache with the same address as the scr record. It was fairly easy to write a routine that automatically reloaded the page when I could not find the image in cache, but one of the things I want to address in my latest revision is this issue.

I have a routine that allows me to run through all of the URL's for the files stored in the internet cache and using that I can figure out the correct URL for a picture, but this seems to me to be about as cumbersome as reloading the page and can be time consuming if the page has a lot of images.I can cut down on the time if I modify the routine to only run through the list on exceptions, but this just seems inefficient to me, especially since I have to make an assumption about what part of the image URL's are the same. What I'd like to do is to track the sources of the images as the web page is being drawn so that I have a listing of all the real source URL's for the images instead of having to rely on what is referenced in the src attribute.

View 5 Replies

SelectList Cached By AJAX?

Sep 20, 2011

I have a DropDownList in MVC which grabs a SelectList initialized and populated by a controller. The goal of the specific page that said list resides on is to reply "You have selected option X" immediately to the user without refreshing (using Ajax).The problem I'm running into is that for some odd reason, while the dropdown renders properly and even posts back correctly, any attempts to add new options or modify previous response messages are in vain.

My View:
<script type="text/javascript" src="../../Scripts/MicrosoftAjax.js"></script>
<script type="text/javascript" src="../../Scripts/MicrosoftMvcAjax.js"></script>

[code].....

View 1 Replies

Cached Objects Staying In Memory?

Mar 24, 2010

I have a asp.net web forms app that uses System.Web.Caching.Cache to cache xml data from a number of web services for 2 hours.

webCacheObj.Remove(dataCacheKey)
webCacheObj.Insert(dataCacheKey, dataToCache, Nothing, DateTime.Now.AddHours(2), Nothing)

Every 90 minutes a Microsoft Search Server hits a particular (spider) page which calls the code to put the objects into the cache.The issue i have is that over a period of time, the memory usage of the application grows exponentially. Lets say that in a week, the memory usage of the application pool grows to over 1gb

View 1 Replies

Repeater And Cached Dataset - Only Last Row Shown?

Jan 13, 2012

I have a relatively simple piece of code as follows:

Dim oShow As DataSet = Nothing
Dim cacheKey As String = String.Format("AsyncCacheFor_agenda_{0}", ShowID)
If Not IsNothing(Cache(cacheKey)) Then

[code].....

View 2 Replies

Implement A Non-cached File Copy Using 2005?

May 7, 2009

I have a program I wrote that copies select files from one remote computer to another.
The set up I for testing is, one computer(a) at home running the program connected to my work's network via VPN and two computers(b,c) at work side by side on the same network. I am trying to copy the files on computer b to computer c, while the program is running on computer a.

The only thing wrong with this is, the files seem to be caching to a temp folder on computer a then going to computer c. When it should be going straight from computer b to computer c. Is there a way to keep the files from trying to cache on the computer running the app?

View 1 Replies

Keeping Tables Cached On Server In Project

Mar 7, 2010

I have an ASP.NET project which is a front-end to a database. In addition to the large tables, the DB contains a few small tables to help normalize the larger tables with common values. I have a VB.NET project which loads the smaller tables into memory, using "Shared" (i.e., "static" in C#) member variables, and uses them. I have a call to load the tables in Global.asax - Application_Start. This works for a while. That is, Application_Start runs when I first run my project, loads the cached values, and will correctly keep them in memory for a while.

What I'm seeing (when running my project via Visual Studio 2008 Debugger, hosted locally) is:

A) The Application_Start code will run more than once. Not in a row, but after the user has navigated to some other pages, I'll see (my breakpoint in) another call to initialize the cache, coming form Application_Start. Is it expected?

B) The "Shared" variable that was set to True when the cache was initialized is now False again (which should only happen when the class is first loaded). Similarly, all the data that was chached is no longer present. That is, it looks like VB is unloading all the Shared members. Is this expected?

View 1 Replies

Syntax To Change The Value Of A Cached Object Property?

Jun 6, 2010

In an ASP.NET 3.5 VB web app, I successfully manage to cache an object containing several personal details such as name, address, etc. One of the items is CreditNum which I'd like to change in the cache on the fly. Is there a way to access this directly in the cache or do I have to destroy and rebuild the whole object just to change the value of objMemberDetails.CreditNum?The cache is set using:

Public Shared Sub CacheSet(ByVal key As String, ByVal value As Object)
Dim userID As String = HttpContext.Current.User.Identity.Name
HttpContext.Current.Cache(key & "_" & userID) = value
End Sub

View 1 Replies

Cached Entities Making Round Trip To Database?

Jan 9, 2012

i am caching objects, if i make linq queries on cached entities then... will theses queries make database round trip due to lazy loading in Entity framework?

View 1 Replies

RemoveAll Is Also Changing Previously Cached Data That It Should Not Be Able To Change?

Apr 28, 2011

This has been driving me insane all day and I think I have the problem narrowed down, but it just doesn't make sense how it could be happening. I have 2 public shared functions and 2 private shared functions. One provides a list of custom objects and one filters the objects based on some parameters in the function call. Both return List(of custom object). The 2 private shared functions are the predicate functions used in the List(of t).RemoveAll function.

[Code]...

Now, the next time I call the GetItemList function it only returns 50 item objects, not the 100 item objects that it should be returning due to the cache being set! I have verified this in the debugger and by running many, many different tests to see what combinations of parameters may be causing the problem. In my testing, as soon as one of the .RemoveAll functions is used the GetItemList item list will get set to whatever the NarrowItemList function returned.

Even if the cache wasn't being set correctly, shouldn't it just get the data again from the database and return 100 items again? What could I be missing???

View 2 Replies

UserPrincipal.Current.ChangePassword Does Not Update Cached Credentials

Jun 29, 2010

I'm writing a program which assists users update passwords for our windows systems and some other applications. Everything is working except when I call the UserPrincipal.Current.ChangePassword command cached credentials are not updated like they are when you change a password using the windows OS password change.

That is: when a remote user who is VPN'd in uses my application to change passwords, when they reboot and VPN is disconnected, they are forced to login to windows using there old password.

Is there a way I can force windows to update the cached credentials to the new password so upon reboot they are able to login using this new password?

View 1 Replies

Web Browser Control Working Offline - (Cached Web Pages) Only?

Aug 18, 2011

Is there a way to work the web browser control for viewing off-line (Cached web pages) only? Is it possible to view cached web pages from IE9 on a web browser control off-line? The reason i am asking this question is because IE9 automatically switches from off-line mode to on-line mode when it cannot find something in the cache by default. For forensic purposes this is not acceptable for these reasons: Active content (Viruses, java script, activex cookies etc)

View 1 Replies

Fastest Alternative To Datatable.Select To Narrow Cached Data?

Sep 28, 2009

I have a search function on my company's website (based on .NET 2.0) that allows you to narrow the product catalog using up to 9 different fields. Right now, after you make your selections on the frontend I am building a dynamic query and hitting the database (SQL Server) to get the resulting list of items numbers. I would like to move away from hitting the database everytime and do all of this in memory for faster results. Basically a 3500 - 4500 row "table" with 10 columns: the item number (which could be a primary key) and the 9 attribute fields (which have repeating values for many many rows).

There can be any number of different searches between the 9 columns to get the items you want:
Column A = 'foo' AND Column D = 'bar'
Column B = 'foo' AND Column C = 'bar' AND Column I = 'me'
Column H = 'foo'
etc...

Based on my research, the .Select() function seems like the slowest way to perform the search, but it stands out to me as being the quickest and easiest way to perform the narrowing searches to get the list of item numbers:
MyDataSet.Select("Column B = 'foo' AND Column E = 'bar' AND Column I = 'me'")
In my specific case, what method I use as an alternative that has the same narrowing functionality and better performance instead of settling for the datatable.select() method?

View 2 Replies

Strongly-typed Generic Method Invokes Its Argument's Base Class Method Instead Of A Shadowed Method In T?

Oct 19, 2010

Consider a MyForm class that contains a shadowed implementation of Show(). It also contains a CreateForm() method, which accepts an instance of the form and calls the shadowed sub:

[Code]....

View 3 Replies

Sql Server - Rolling Back Entity Framework Transaction, Cached Item Persist?

Aug 23, 2011

I'm using an Entity Framework context, and sometimes would like to create a transaction so that the client can do multiple changes and then commit/rollback them all together.However, if many changes were made, and SaveChanges() was called multiple times, after which a rollback is called, entities that were commited already, will remain the way they were commited, and would not roll back.Here's how my transaction-relative functions look like:

Public Sub BeginTransaction()
Dim context = HttpContext.Current.GetObjectContext()
If Not context.Connection.State = ConnectionState.Open Then
context.Connection.Open()
End If

[Code]...

Not only does the test fail, but it also leave the ObjectContext in an unstable mode, because it still has invalid changes in it.

View 1 Replies

Cached For Exp Use Cache.insert To Cache Each Property ?

Jul 11, 2009

I have the following code in my config.vb file in app folder and almost all of my pages use this code for permormance issues i need to have it cached for exp use cache.insert to cache each property How should i use caching?

BR>Public Class Config

Private _physicalPath As String

Public Property physicalPath() As String

[CODE]..........................

View 3 Replies

Does Calling The Dispose Method On A Windows.Forms.Timer Call It's Stop Method

Nov 12, 2009

Does calling the Dispose method on a Windows.Forms.Timer call it's Stop method? Or should I stop the timer before I dispose it?

View 5 Replies

Inheritance - Create A Method Called StartWorking() And Want FrmChild To Inherit - Method

Nov 25, 2011

I have a large problem with inheritance in vb.net. The problem is the following:

I have 2 forms => frmBase and frmChild

In frmBase i want to create a method Called StartWorking() and i want frmChild to inherit this method.

But here is the tricky thing: when frmChild.StartWorking is called i would like the following => without calling MyBase.StartWorking()

I want frmBase.StartWorking() to be executed first and after a test in frmBase.StartWorking if blnValue is true then frmChild.StartWorking has to be activated. if blnValue is false that frmChild.StartWorking cannot be activated.

View 2 Replies

Use The ToString Method And A Counter To Concatenate A File Name Into A String Variable From The Image.FromFile Method?

Dec 18, 2010

I have nine pictures that I need to animate -I need to use the ToString method and a counter to concatenate a file name into a string variable from the Image.FromFile method. Once the counter reaches its maximum value, and the last picture is displayed, the counter should be reset to zero or one depending on how the first image file has been name. Also a static counter variable should be incremented in the time routine. what I have so far -- I know what I have to do; however, I just do not know how to code this properly.. Right now I have this going thru a button procedure but it needs to go through a timer.

[code]....

View 2 Replies

Constrain A Generic Method / Extension Method To Numeric TYPEs Only?

Sep 16, 2010

Write an overload for every numeric type or if possible constrain a generic extension method to just numeric types.

View 2 Replies

Difference Between My.Computer.FileSystem.WriteAllText Method And The IO.StreamWriter Method?

Jun 2, 2011

I just need to know what is the slight difference between them so I know which one to use everytime.

View 5 Replies







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