|
It is not a matter of calling Dispose or Close in the catch. The problem is that you have an eternal loop and, inside the loop, you have a try/catch accessing an object that may be disposed.
That means:
You start running it OK. As soon as the client disconnects, you receive an exception, you catch it, maybe you close/dispose objects, it doesn't matter, the loop runs again, you try to access a disposed object, you get a new exception, you catch it, you dispose again (nothing changes) and you run again... infinitely.
So, with a while(true) and a try/catch inside the while, you will always make the application consume 100% CPU when you have as many disconnected clients as you have CPUs (that is, on a 4-cpu machine, the CPU will go up to a total near of 100% as soon as 4 clients disconnect, as you simply don't allow the code to exit the eternal loop).
|
|
|
|
|
Hi, Avoid creating too many instances using new keyword. If you still need then dispose them once used immediately.
ravindrapc
|
|
|
|
|
hi all I developing a program in c#, I have two form. in the form1 I have a texbox, label and combobox, and in the second form I have a button the name cleaning and the class clean.I need is calling me class clean with me button clean and cleaning the form 1
|
|
|
|
|
Sorry?
That doesn't make a whole lot of sense - what does your Clean class have to do with Form1?
If you mean "I want to press a button on Form2, and it empties the data on Form1" then it depends who opened what.
IF Form1 opened Form2, then you need an event in Form2, which is handled in Form1: Transferring information between two forms, Part 2: Child to Parent[^] - Form1 then clears out it's own fields.
If Form2 opened Form1, then use a method in Form1 which is called from Form2, and which clear out teh info: Transferring information between two forms, Part 1: Parent to Child[^] - the example uses a property, but a method is more appropriate.
If neither of them knows about the existence of the other (i.e. both were opened from Form3) then combine the two methods: Transferring information between two forms, Part 3: Child to Child[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
in my form1 I have a texbox and I want to clean from my button clean in my form 2 whit my class clean
I think is the is the second opcion
|
|
|
|
|
Assume you create a Windows Class Library, 'MyLibrary'; you create a Windows Form project 'MyProject;' you add a reference to MyLibrary's .dll to MyProject.
If MyLibrary has a static variable, 'MyVar,' every instance of MyLibrary in MyProject will, of course, access the one-and-only MyVar.
However, what if you want each instance of MyLibrary to store a reference to itself that can be accessed from outside the scope of the instance ... as if each instance of MyLibrary had a unique static value ?
Perhaps there is a way using separate Application Contexts ?
Will add code samples, shortly (hardware problems, here).
thanks, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
I'm not sure I get how that would work. If you are accessing an instance from outside that instance, how could you tell which instance you were actually accessing?
The only thing I can come up with that comes close, that I actually have used in the past, is a static Dictionary, where the keys are some sort of instance identifier, and the value is the instance itself. The constructor adds itself to that dictionary, and Dispose or some sort of release method removes it again.
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
Maybe I don't get it but there is only one instance of a DLL in a process.
However, a DLL might use Thread Local Storage (Windows)[^] so that each thread of a process has access to it's own data.
|
|
|
|
|
You're over thinking it. A static variable has nothing to do with any instance of a class, the point of static means it's tied to the Class and not the Instance.
For example
class ClassName {
static string VariableName;
}
it wouldn't matter if you said..
ClassName newInstance = new ClassName();
newInstance.VariableName = "test";
or if you said
ClassName.VariableName = "test";
In both instances, you're dealing with the same thing.
If you want to have a variable tied to an instance, you shouldn't mark it as static. In that way, each instance of ClassName would have it's own instance of VariableName
Hope that helps!
|
|
|
|
|
DataSet ds = new DataSet();
conn_DB();
OracleCommand Cmd = null;
Cmd = new OracleCommand();
Cmd.Connection = mConn;
try
{
string sql = "SELECT * FROM USER_INFO WHERE USE_UID='" + userid + "'" + " AND PWD='" + userpw + "'";
Cmd.CommandText = sql;
OracleDataAdapter adapter = new OracleDataAdapter(Cmd);
adapter.Fill(ds);
}
catch (OracleException e)
{
return null;
}
How to fix "
System.InvalidOperation.Exception"
or Exception "
modified 7-Nov-16 2:36am.
|
|
|
|
|
You set Cmd to Null, create a new command called navicallCmd, set it up then pass Cmd as the argument to the adapter...try passing navicallCmd.
|
|
|
|
|
Just to add to what Micheal says, don't do it like that either: Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
I'm using parallel arrays to display names and grades of students. I am stuck at displaying the arrays. I get System.String[] instead of the input value I want. This is my code what am I doing wrong:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Parrallel_Arrays {
public partial class frmGrades : Form {
String nameString = "Aaron Ben Carmelina Dorethy Erinn Karin " +
"Lester Mitsue Nichol Ria Sherie Zachary";
String assignmentsString = "44 92 100 100 100 97 100 95 100 0 100 100 " +
"95 95 97 90 100 95 100 100 100 100 100 75 " +
"98 100 65 0 100 100 100 100 100 100 95 75 " +
"85 100 0 50 100 95 90 0 80 100 100 100";
String[] arrayNames = new String[12];
String[,] arrayGrades = new String[4, 12];
String[] arrayAverage = new String[12];
public frmGrades() {
InitializeComponent();
}
private void frmGrades_Load(object sender, EventArgs e) {
}
//Method to Fill Array
private void FillArray(String[] name, String[,] grade) {
String[] arrayNames = { nameString };
String[,] arrayGrades = { { assignmentsString } };
String[] arrayAverage = { };
char[] separator = new char[] { ' ' };
String[] tokens = assignmentsString.Split(separator);
String[] token2 = nameString.Split(separator);
foreach (String token in tokens) ;
}
//Method to Display Array of names and assignment grades
private void DisplayArray(String[] nameString, String[,] assignmentsString) {
for (int i = 0; i < nameString.Length; i++) {
lbxDisplay.Items.Add(nameString[i] + " ");
}
}
|
|
|
|
|
String[] arrayNames = { nameString };
You cannot assign a string to an array like that. You must create the array first, or use String.Split [^] to separate the individual fields.
|
|
|
|
|
Just to back up what Pete Richard says, this code:
String[] arrayNames = { nameString }; Doesn't do what you think.
When you use this construct:
string[] x = {...} You are telling the system that each item inside the "{" and "}" is to be treated as a single string - so if it isn't a string already, the system will apply an implicit conversion:
String[] arrayNames = { nameString.ToString() }; Since nameString is an array and the Array class doesn't provide an explicit ToString override, the default object ToString implementation is used instead, which returns the name of the class instead of the content: "System.String[]"
As Pete says, use Split instead:
String[] arrayNames = nameString.Split(' ');
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 7-Nov-16 6:51am.
|
|
|
|
|
OriginalGriff wrote: what Pete says Who he?
|
|
|
|
|
You want accuracy on a Monday morning?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I am working on datagridview control in c# . I have three columns and I want to add the values from the first and second columns to get the value on the third column
|
|
|
|
|
|
Hi guys,
I've been struggling with a list inside a list. I have a table "cart_product" that contains 2 columns: cart_id and product_id.
Also I have a product table "product" with al the information of a product ( name, product_id, price etc ). I want to get the product information when I read the cart from the website, so I can show the price, name etc.
The problem I have is that I can't combine the 2 classes that I've made. If I use them separate its works correctly but combining them wont work..
public void Fetch()
{
database.Query("SELECT * FROM ws_cart_product WHERE cart_id=?cart_id;");
database.Add("?cart_id", cart_id);
foreach (DataRow row in database.FetchAsDataTable().Rows)
{
cart_id = global.ParseInt(row["cart_id"].ToString());
if (row["product_id"] != DBNull.Value)
{
product_id = global.ParseInt(row["product_id"].ToString());
}
if (row["parent_id"] != DBNull.Value)
{
parent_id = global.ParseInt(row["parent_id"].ToString());
}
if (row["quantity"] != DBNull.Value)
{
quantity = global.ParseInt(row["quantity"].ToString());
}
Product product = new Product();
product.product_id = global.ParseInt(row["product_id"].ToString());
product.Fetch();
}
}
public void Fetch()
{
StringBuilder query = new StringBuilder();
query.Append("SELECT *, ");
query.Append("(");
query.Append("SELECT thumbnail ");
query.Append("FROM ws_product_file, file ");
query.Append("WHERE file.file_id=ws_product_file.file_id ");
query.Append("AND ws_product_file.product_id=ws_product.product_id ");
query.Append("AND file.status_id=1 ");
query.Append("ORDER BY sortorder DESC LIMIT 0,1");
query.Append(") ");
query.Append("AS thumbnail, ");
query.Append("(");
query.Append("SELECT mimetype ");
query.Append("FROM ws_product_file, file ");
query.Append("WHERE file.file_id=ws_product_file.file_id ");
query.Append("AND ws_product_file.product_id=ws_product.product_id ");
query.Append("AND file.status_id=1 ");
query.Append("ORDER BY sortorder DESC LIMIT 0,1");
query.Append(") ");
query.Append("AS mimetype ");
query.Append("FROM webpage, ws_product ");
query.Append("WHERE webpage.status_id=1 ");
query.Append("AND webpage.webpage_type_id=4 ");
query.Append("AND ws_product.product_id=webpage.webpage_type_content_id ");
query.Append("AND ws_product.product_id=?product_id; ");
database.Query(query.ToString());
database.Add("?product_id", product_id);
foreach (DataRow row in database.FetchAsDataTable().Rows)
{
product_id = global.ParseInt(row["product_id"].ToString());
if (row["parent_id"] != DBNull.Value)
{
parent_id = global.ParseInt(row["parent_id"].ToString());
}
if (row["status_id"] != DBNull.Value)
{
status_id = global.ParseInt(row["status_id"].ToString());
}
if (row["create_date"] != DBNull.Value)
{
create_date = global.ParseDateTime(row["create_date"].ToString());
}
if (row["product_no"] != DBNull.Value)
{
}
}
}
If I run them seperate the result would become:
{Dotcontent.CartProduct}
cart_id: 1
product_id: 64
parent_id: 0
quantity: 2
customer_id: 0
guid: null
{Dotcontent.Product}
webpage_id: 145
website_id: 0
status_id: 1
url: "mode360-composer-fotostudio-fa40"
type: null
webpage_type_id: 0
webpage_type_content_id: 0
version: 0
language_id: 0
parent_id: 0
related_webpage_id: 0
title: "Mode360 Composer Fotostudio FA40"
text: null
short_description: null
meta_description: null
published_from: 1-1-0001
published_to: 1-1-0001
created_on: 1-1-0001
created_by: 0
product_id: 64
create_date: 16-9-2016
product_no: "291610"
ean: ""
price_on_request: False
weight: 0
brand_id: 0
in_export: False
template_id: 1
mimetype: "image/jpeg"
thumbnail: "iVBORw0KGg
price: 0
old_price: 0
label: "Tijdelijke aanbieding"
quantity: 0
CartProduct cart = new CartProduct();
cart.cart_id = 1;
cart.Fetch();
Response.Write("<pre>" + ObjectDumper.Dump(cart) + "</pre>");
Product product = new Product();
product.product_id = cart.product_id;
product.Fetch();
Response.Write("<pre>" + ObjectDumper.Dump(product) + "</pre>");
|
|
|
|
|
Message Removed
modified 4-Nov-16 4:40am.
|
|
|
|
|
I made it but ı have a problem.For example a string aaaabbbccccc like this which compress by RLE first then 4a3b5c compress by huffman and output is .huf binary file,no problem here.But when ı want to decompress .huf file by huffman then aaaabbbccccc but it's wrong which must be 4a3b5c then rle decompress and the our orginal text.Why it is like this ?
|
|
|
|
|
Rıza Berkay Ayçelebi wrote: Why it is like this ? Because you have a problem with your logic in your code. Without any code, that's as close as we can get to an answer I'm afraid.
This space for rent
|
|
|
|
|
Most likely you are passing the original string into your huffman routine, rather than the RLE output.
|
|
|
|
|