|
Hi,
Which one is faster ?? Value Type or Reference Type.
Regards,
Hatim Ali.
|
|
|
|
|
hi,
I don't know in which sence that you are asking 'Value Type or Reference Types are fast'. I recommand you to read some C# syntax and C# basics.
Value type and reference types are two type of Common Type System. We can say all numeric types are value type and which are stored in stack memory. Variables of reference types, referred to as objects, store references to the actual data. Reference type store data in Managed Heap memory.
And the visibility of both types are entirly different.
In some cases we need to convert value type to reference type or reverse. So this is also possible.
Converting value type data into reference type data is called BOXING.
Converting Reference type data into value type data is called UNBOXING.
I recommand you to read MSDN or some book which explain the C# language.
**************************
S r e e j i t h N a i r
**************************;)
|
|
|
|
|
Objective answer: Value types are faster.
Notes:
If you have a finite (and preferably short) storage requirement, value types (for example a structure) are your best friends. But use them lavishly and you will end up with a Stack overflow.
|
|
|
|
|
Here is my problem:
I have done a web application; on this web application you can start a "slideshow". This slideshow consists of four pages that display data in tables and graphs. Each page get a lot of data from the database (SQL Server) and some of the pages use a lot of nestled ArrayLists to calculate the data before it's presented. Everything is done in c# and I use the data application block from MS.
The problem: I start the problem and the pages are displayed fine (the user can choose the delay in seconds before the next page are displayed, in this case 10 seconds). After 30 minutes - x hours Internet Explorer just hangs (the whole page turns white and no code is executed). No error turns up in my errorlog either.
I thought it had something to do with IE, so I've started to do a Windows Form application of this instead. The same (?) problem happens again. The program eats CPU and after 30-60 minuts the CPU is at 100% and the application almost stalls. I have run CLR Profiler but I don’t know how to read the results.
Can anyone help me how to get further with this problem? I’m starting to think if I have the same problem both on my web application and on my windows application? And if so, what is eating CPU? The pages are really simple, no multithreads, just get data in a dataset, transform the data and display it?
Thanks for any help, tips how to get further!
Rgds,
Stefan
|
|
|
|
|
Could you either post or send that code so that we can see? It's hard to pinpoint your problem when its like this without seeing it.
Steve Maier, MCSD MCAD
|
|
|
|
|
 I got a tip that it might be that fact that I never dispose my datasets.
I have tried to dispose all datasets both in the windows version and the web version. No luck with the windows application though, still eats CPU.
When I test this I only use one page so the code is quite simple. We have one Main form that handles what page to show etc and one subform that displays the data.
Here is the code that is executed every 10 seconds from the main form:
private void timer2_Tick(object sender, System.EventArgs e)<br />
{<br />
YO.WindowState = FormWindowState.Maximized;<br />
TS.WindowState = FormWindowState.Maximized;<br />
MG.WindowState = FormWindowState.Maximized;<br />
DG.WindowState = FormWindowState.Maximized;<br />
<br />
string sTime = dataContainer.getTime().ToString();<br />
string sLimit = dataContainer.getLimit().ToString();<br />
string sVolume = dataContainer.getVolume().ToString();<br />
string sPages = dataContainer.getPages();<br />
string sProducts = dataContainer.getProducts();<br />
string sUnits = dataContainer.getUnits();<br />
<br />
ArrayList arrPages = YieldMonitorEngine.ExtractPages(dataContainer.getPages());<br />
ArrayList arrProducts = YieldMonitorEngine.ExtractProducts(dataContainer.getProducts());<br />
<br />
switch (int.Parse(sPageToView))<br />
{<br />
case AppConstants.MONITOR_YIELD_OVERVIEW: <br />
<br />
YO.InitializePage (int.Parse(sPageToView), int.Parse(sProductToView), int.Parse(sTime), <br />
double.Parse(sLimit), int.Parse(sVolume), sPages, sProducts, sUnits);<br />
MG.Hide();<br />
DG.Hide();<br />
TS.Hide();<br />
YO.Show();<br />
YO.Refresh();<br />
YO.Update();<br />
break;<br />
case AppConstants.MONITOR_YIELD_DETAILS_MONTHLY_GRAPH:<br />
MG.InitializePage (int.Parse(sPageToView), int.Parse(sProductToView), int.Parse(sTime), <br />
double.Parse(sLimit), int.Parse(sVolume), sPages, sProducts, sUnits);<br />
MG.Show();<br />
MG.Refresh();<br />
MG.Update();<br />
YO.Hide();<br />
DG.Hide();<br />
TS.Hide();<br />
break;<br />
case AppConstants.MONITOR_YIELD_DETAILS_DAILY_GRAPH:<br />
DG.InitializePage (int.Parse(sPageToView), int.Parse(sProductToView), int.Parse(sTime), <br />
double.Parse(sLimit), int.Parse(sVolume), sPages, sProducts, sUnits);<br />
DG.Show();<br />
DG.Refresh();<br />
DG.Update();<br />
YO.Hide();<br />
MG.Hide();<br />
TS.Hide();<br />
break;<br />
case AppConstants.MONITOR_TOP_SYMPTOMS:<br />
TS.InitializePage (int.Parse(sPageToView), int.Parse(sProductToView), int.Parse(sTime), <br />
double.Parse(sLimit), int.Parse(sVolume), sPages, sProducts, sUnits);<br />
TS.Show();<br />
TS.Refresh();<br />
TS.Update();<br />
YO.Hide();<br />
MG.Hide();<br />
DG.Hide();<br />
break;<br />
}<br />
<br />
<br />
string sLastViewedProduct = sProductToView;<br />
string sLastViewedPage = sPageToView;<br />
<br />
int iIndexOfLastViewedProduct = arrProducts.IndexOf(sLastViewedProduct.ToString());<br />
<br />
if (iIndexOfLastViewedProduct + 1 < arrProducts.Count) <br />
{<br />
sProductToView = arrProducts[iIndexOfLastViewedProduct + 1].ToString();<br />
sPageToView = sLastViewedPage;<br />
}<br />
else <br />
{<br />
sProductToView = arrProducts[0].ToString();<br />
<br />
int iIndexOfLastViewedPage = arrPages.IndexOf(sLastViewedPage.ToString());<br />
<br />
if (iIndexOfLastViewedPage + 1 < arrPages.Count) <br />
{<br />
sPageToView = arrPages[iIndexOfLastViewedPage + 1].ToString();<br />
}<br />
else <br />
{<br />
sPageToView = arrPages[0].ToString();<br />
}<br />
}<br />
<br />
arrPages.Clear();<br />
arrProducts.Clear();<br />
}
When I test the application I only test with the case AppConstants.MONITOR_TOP_SYMPTOMS, so that's the code that is executed. The TS.InitializePage code looks like this:
public void InitializePage (int iPageToView, int iProductToView, int iTime, double dLimit, int iVolume,<br />
string sPages, string sProducts, string sUnits) <br />
{<br />
dgUnit1.DataSource = null;<br />
dgUnit2.DataSource = null;<br />
dgUnit3.DataSource = null;<br />
dgUnit4.DataSource = null;<br />
<br />
DateTime dtTestDate = DateTime.Parse(DateTime.Now.AddDays(iNoDaysFromTodayToView).ToShortDateString());<br />
ArrayList arrProducts = YieldMonitorEngine.ExtractProducts(sProducts);<br />
ArrayList arrUnitGroups = YieldMonitorEngine.ExtractUnitGroups(sUnits);<br />
<br />
ArrayList arrUnitsForProduct = YieldMonitorEngine.ExtractUnitsForProduct(iProductToView, arrProducts, arrUnitGroups);<br />
<br />
DataSet dsProduct = YieldMonitorEngine.GetProductInfo(iProductToView);<br />
<br />
if (dsProduct != null && dsProduct.Tables[0].Rows.Count > 0) <br />
{<br />
string sModelName = dsProduct.Tables[0].Rows[0][DBConstants.PRODUCT_MODEL].ToString();<br />
<br />
lblTitle.Text = "Top Symptoms for " + sModelName + " - " + dtTestDate.ToString("MMMM d, yyyy");<br />
}<br />
<br />
if (arrUnitsForProduct.Count > 0) <br />
{<br />
dgUnit1.Visible = true;<br />
InitializeDataGrid(int.Parse(arrUnitsForProduct[0].ToString()), iProductToView, dtTestDate, dgUnit1, lblUnit1, dLimit, iVolume);<br />
}<br />
else <br />
{<br />
dgUnit1.Visible = false;<br />
}<br />
<br />
if (arrUnitsForProduct.Count > 1) <br />
{<br />
dgUnit2.Visible = true;<br />
InitializeDataGrid(int.Parse(arrUnitsForProduct[1].ToString()), iProductToView, dtTestDate, dgUnit2, lblUnit2, dLimit, iVolume);<br />
}<br />
else <br />
{<br />
dgUnit2.Visible = false;<br />
}<br />
<br />
if (arrUnitsForProduct.Count > 2) <br />
{<br />
dgUnit3.Visible = true;<br />
InitializeDataGrid(int.Parse(arrUnitsForProduct[2].ToString()), iProductToView, dtTestDate, dgUnit3, lblUnit3, dLimit, iVolume);<br />
}<br />
else <br />
{<br />
dgUnit3.Visible = false;<br />
}<br />
<br />
if (arrUnitsForProduct.Count > 3) <br />
{<br />
dgUnit4.Visible = true;<br />
InitializeDataGrid(int.Parse(arrUnitsForProduct[3].ToString()), iProductToView, dtTestDate, dgUnit4, lblUnit4, dLimit, iVolume);<br />
}<br />
else <br />
{<br />
dgUnit4.Visible = false;<br />
}<br />
<br />
dsProduct.Dispose();<br />
arrProducts.Clear();<br />
arrUnitGroups.Clear();<br />
arrUnitsForProduct.Clear();<br />
}<br />
<br />
<br />
private void InitializeDataGrid(int iSupplyUnitID, int iProductID, DateTime dtTestDate, DataGrid dgUnit, Label lblUnit, double dSymptomLimit, int iMinStationVolume)<br />
{<br />
try <br />
{<br />
DataSet dsSupplyUnit = YieldMonitorEngine.GetSupplyUnitInfo(iSupplyUnitID);<br />
if (dsSupplyUnit != null && dsSupplyUnit.Tables[0].Rows.Count > 0) <br />
{<br />
lblUnit.Text = dsSupplyUnit.Tables[0].Rows[0][DBConstants.SUPPLY_UNIT_SHORT_NAME].ToString();<br />
}<br />
<br />
DataSet dsTopSymptoms = YieldMonitorEngine.GetSymptomYieldDailySUMTopSymptoms(iSupplyUnitID, iProductID, dtTestDate, dSymptomLimit, iMinStationVolume);<br />
dsTopSymptoms.Tables[0].TableName = "TopSymptoms"; <br />
dgUnit.DataSource = dsTopSymptoms.Tables["TopSymptoms"];<br />
<br />
if (dsTopSymptoms.Tables["TopSymptoms"].Rows.Count == 0)<br />
{<br />
dgUnit.Visible = false;<br />
}<br />
else<br />
{<br />
dgUnit.Visible = true;<br />
}<br />
<br />
dsTopSymptoms.Dispose();<br />
dsSupplyUnit.Dispose();<br />
<br />
dgUnit.Enabled = false;<br />
<br />
DataGridTableStyle dgts = new DataGridTableStyle();<br />
<br />
dgts = new DataGridTableStyle();<br />
dgts.MappingName = "TopSymptoms";<br />
<br />
dgts.AlternatingBackColor = Color.LightGray;<br />
<br />
DataGridTextBoxColumn TextCol = new DataGridTextBoxColumn();<br />
TextCol.MappingName = "SymptomName";<br />
TextCol.HeaderText = "Symptom";<br />
TextCol.ReadOnly = true;<br />
TextCol.Width = 250;<br />
dgts.GridColumnStyles.Add(TextCol);<br />
<br />
TextCol = new DataGridTextBoxColumn();<br />
TextCol.MappingName = "StationName";<br />
TextCol.HeaderText = "Station";<br />
TextCol.ReadOnly = true;<br />
TextCol.Width = 250;<br />
dgts.GridColumnStyles.Add(TextCol);<br />
<br />
TextCol = new DataGridTextBoxColumn();<br />
TextCol.MappingName = "YieldLossTest1";<br />
TextCol.HeaderText = "Yield Loss";<br />
TextCol.Format = "P";<br />
TextCol.ReadOnly = true;<br />
TextCol.Width = 250;<br />
dgts.GridColumnStyles.Add(TextCol);<br />
<br />
dgts.RowHeadersVisible = false;<br />
<br />
dgUnit.TableStyles.Clear(); <br />
<br />
<br />
dgUnit.TableStyles.Add(dgts);<br />
}<br />
catch (Exception ex) <br />
{<br />
string ssfsfs = "";<br />
}<br />
}
Can it be that I for some reason have some objects that I havn't disposed that I should? I thought .NET handled this automatically but seems like it wasn't that easy?
|
|
|
|
|
Dear CPians,
I have a problem within my ASP.NET application. The reason I am posting it on this Forum is that the problem is not Web related, its 100% C#.
I upload an image and I create an Image object from it. I do some Image manipulation like rescaling, rotating etc. and I create a Bitmap object from it.
Then I create another Bitmap object which is the Thumbnail of the first one.
I end up with two Bitmap objects. The original one and the thumnail. Now I need to save the two into the DataBase, (SQL Server 2000).
How can I convert the two Bitmap objects into byte arrays (byte[])? Any ideas?
Thanking you in advance!
theJazzyBrain
Excellence is not an act, but a habit! Aristotle
|
|
|
|
|
|
How can i get system information, such as ip adresses,hdd properties, directories...etc of a local computer?
Can u give some examples?
Please help me
Tahnks everybody
|
|
|
|
|
For example:System.Windows.Forms.MessageBox.Show(Environment.CurrentDirectory);
|
|
|
|
|
You would have to get most, if not all, of this information using the System.Management namespace and WMI (Windows Manangement Instrumentation).
You can find examples of this on CP if you just search the Articles for 'WMI'. One example is right here[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I made an addin by using the Addin-Wizard of Visual .NET.
I should like to install this addin on the next configuration:
- A PC with Windows XP
- there can be several users, but they haven't administrator rights.
- The installation of the addin must work in the administrator mode, but users should use it in restricted mode (not admin mode in Windows XP).
So, I have problems, because the addin fail when it is launched in restricted mode.
Visual .Net print the addin failed during the loading.
Do you know a solution for this problem ?
|
|
|
|
|
i have problem with these topics:
why we r put signing key for the assebly.
ok i have created a class library called empobject.it's locating F:\KeyTest\EmpObject
then i have assign a key:
D:\WINDOWS\System32>sn -k F:\KeyTest\EmpObject\mykey.snk and the key is generated.then i have create a folder called SpecialLib in
D:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\SpecialLib cas
i want to copy all the non standard component here.
then i promt D:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\SpecialLib>gacutil -i empobject.dll.
but thr was a error called
Microsoft (R) .NET Global Assembly Cache Utility. Version 1.0.3705.0
Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.
Failure adding assembly to the cache: Attempt to install an assembly without a strong name
|
|
|
|
|
hi,
Did you mention the strongkey name and location in AssemblyInfo.cs file of your .dll project.
Eg. please mention the vales for the below mentioned assembly attributes.
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
After mentioning this. Try to compile your .dll file once again and then use Gacutil to install this .dll into GAC.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
ya i don't have idea about the
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
|
|
|
|
|
hi,
You will get this attibute on your AssemblyInfo.cs file which is located in your .dll project directory.
Before compiling your .dll you need to mention your strongkey file name and location. Just mention these information here and compile your assembly.
After your successful compilation you can go for Gacutil.
Eg.
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("C:\\Sreejit.snk")]
[assembly: AssemblyKeyName("Sreejit.snk")]
Here
AssemblyKeyFile - > the location where my Strongkey file is locating.
AssemblyKeyName - > is the name of strong file.
Try to compile your .dll after mentioning these two attribute. After this you can gacutil to install your .dll into GAC.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
hello mr.sreejithnair,
Sorry about the mail.anyway i have install it sucessfully
but still i can't put it to the my own dir.cas i have create a dir
in my c:\.wht i want is copy all the non standard asemblies here.
thanx
amal
|
|
|
|
|
hi,
You wrote :
Sorry about the mail.
Nevar a problem. I won't encourage personal mails.
You can submit your doubt here in discussion. Sometimes this may help others.
I can't properly figurout what you mean by "non standard asemblies".
Tell me what is your real requirement.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
i just want to keep my own dll's in another seperate folder other than c:\windows\assembly.
and i have open a new project and i have to add reference above dll.
but my empobject.dll is not display in the component list under the .net tab.
but other standard dll's(Crystalreportplugindil) list thr.so wht was the problem.
amal
|
|
|
|
|
hi,
According me ,after completing your this requirement you need to study something about C# assemblies. Especially private and public assemblies.
The assemlies which are installed in GAC will show in the component list. But here you kept your assembly in your own location ( NOT IN GAC ). So it is upto you to locate the location of the .dll file.
Here what you can do is , Right click the reference folder and try to select add reference. Here you need to browse the location of your .dll file ( C:\yourDir\aaa.dll) and open.
So click on browse button and try to locate, open the .dll file.
After this you will came to know that your .dll is there in reference folder of your application.
Finally don't forget to study about Private and Shared Assemblies.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
hi,
I want to point a function which will take some parameter to ThreadStart delegate. I found that the default implimentation is not overridable.
Here what i will do if i want to put the execution of my function into a thread.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
|
hi,
Please little bit more clear.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
I just posted this very same answer in the VB.NET Forum today. Here's[^] the link. I know, I'll get flamed for this, but I hate writing the same code twice...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I pretty bad in vb.net. Is it possible to show in in C#.net.;)
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|