|
Hi.
Could you please guide me , how I can access to this item[^] text in a ListView ?
Thank you.
|
|
|
|
|
Listview.Items[RowIndex].SubItems[ColIndex]
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
|
Vs2005 .net v2
Hi I have a number of windows client applications which use web services to send and receive data.
When a client starts it could be active for 5 minutes or 5 hours..
When the client first loads it instanciates a web service and calls its methods the client could make hundreds of calls to various web service methods.
- this instanciation remains until the user logs out of the client.
So the client instanciates the web service only once - is this the correct way or should I be instanciating the web service before every method call then clearing up? - and would there be a substancial performance hit this way?
The problem im getting is that the web service occasionally hangs (for all clients) and I have to recycle the app pool to get it running again.
Thanks in advance
|
|
|
|
|
Overall, reusing the item seems to make sense to me, so long as it doesn't leak memory. Does it always take a long time to hang ? Perhaps it is leaking resources ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
In my opinion:
1) a client instanciatees a 'web service's proxy class' object only once.
2) once the client connect the web serivce( calls a method), it will instanciate a 'socket' object(or 'networkstream' object, to send 'cmd' and get the result from the web serivce), and when get the result datas, the 'socket' will be cleared up by framework2.0.
3) so 'web service's proxy' object is once, 'socket' objects are several times, when a method called.
modified 27-May-14 5:33am.
|
|
|
|
|
I'm working in an application wich works with more than 100 threads belonging to ThreadPool in a common job, so I create the WaitCallback object pointing to a method, next from the Main Thread with a For sentence I start creating Threads, and I see:
1) if all the execution procedure is self-contained in the method called with the WaitCallBack object, ever thread start working from it´s creation an everything works correctly.
2) but if for finish the job the pointed method needs to use any other method outside itself, now the Main Thread takes the complete execution time and no other Thread start working until the Main Thread finish creating all the Threads.
So I don`t know how to avoid using Class or methods externals to the method pointed by the WaitCallback object. And the big quantity of created Threads, without discarging one until the end of creation process in the Main Thread, makes the system blocked before finishing.
|
|
|
|
|
Hi,
I did not understand half of what you said, however the other half leads to these remarks:
1.
The ThreadPool holds a (rather large) number of threads, depending on the Windows version. You can modify it with ThreadPool.SetMaxThreads, which I do not recommend!
2.
"with a For sentence I start creating Threads" sounds horrible; if a number of threads need to execute the same kind of work (which isn't mostly waiting for something), then you should limit the number of those threads to some small number, say 4. Having more than a few threads trying to do similar work will only slow down the overall system, since your app will run into some common bottleneck right away (bus bandwidth, disk I/O, network I/O, cache trashing, or any combination thereof).
3.
Any multithreaded system will malfunction if you have incorrect synchronization; you would need locks to prevent accessing stale data, and too many locks may bring everything to a halt.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I understand that a lot of Threads can easily block the system, so I am using a ThreadPool in order to recovery each thread after finishing their job, but I follow studyng my problem and I see that I´m using method`s and control`s created in a different Thread (using checkforilegalcrossthreads = false) and I believe that it is not a good idea, I am stsrting with Threads and I don´t understand completely the threads rules and way of programming with them.
Thanks
|
|
|
|
|
FJJCENTU wrote: checkforilegalcrossthreads = false
That is a big no no. Please read this[^].
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi
i have 2 tables :
Persons (master)
Images (detail)
each person can multiple images. i'm using tableAdapterManager to accomplish this and here is my code in my DataManager class :
public bool SavePersonWithImages(MyDataSet DataSet)
{
bool saved = false;
if (DataSet.GetChanges() != null)
{
try
{
MyDataSetTableAdapters.PersonsTableAdapter personAdapter = new MyDataSetTableAdapters.PersonsTableAdapter();
MyDataSetTableAdapters.ImagesTableAdapter imageAdapter = new MyDataSetTableAdapters.ImagesTableAdapter();
MyDataSetTableAdapters.TableAdapterManager manager = new MyDataSetTableAdapters.TableAdapterManager();
manager.PersonsTableAdapter = personAdapter;
manager.ImagesTableAdapter = imageAdapter;
int rowAffected = manager.UpdateAll(DataSet);
saved = (rowAffected > 0);
DataSet.AcceptChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
DataSet.RejectChanges();
}
}
return saved;
}
the insert & delete works fine, but my problem when user edit the image with replace that image with new one, it's works successfully, but when i close the form and open it again, it's don't display image! here is my edit button code :
private void barBtnEditPerson_ItemClick(object sender, ItemClickEventArgs e)
{
if (this.personBindingSource.Count > 0)
{
MyDataSet.PersonRow personCurRow = (MyDataSet.PersonRow)((DataRowView)this.personBindingSource.Current).Row;
FrmZamin frm = new FrmZamin(personCurRow, this.amlakDataSet);
personCurRow.BeginEdit();
if (frm.ShowDialog() == DialogResult.OK)
{
this._frmLoading = new FrmWait("Saving data ...");
personCurRow.EndEdit();
DataManager dm = new DataManager();
dm.SavePersonWithImages(this.myDataSet);
this._frmLoading.Close();
this.backgroundWorker1.RunWorkerAsync();
}
else
{
personCurRow.CancelEdit();
}
this.myDataSet.Images.Clear();
}
}
can anybody know where does my problem and how to solve it ?
Note 1 : my database is access 2007
Note 2 : my images dataTable does not have any relation with persons dataTable or some other tables (in my DataSet Designer)
thanks in advance
|
|
|
|
|
Hi
Is it possible to add a new item to a ComboBox when its bound to a DataView? Here's the code I use to fill my ComboBox:
DataView dv = new DataView(someDataTable, "FunctionID > '0'", "Function", DataViewRowState.OriginalRows);<br />
<br />
cboFunctions.ItemsSource = dv;<br />
cboFunctions.DisplayMemberPath = someDataTable.Columns[1].ToString();<br />
cboFunctions.SelectedValuePath = someDataTable.Columns[0].ToString();<br />
cboFunctions.SelectedIndex = 0;
I tried adding a new item like this:
cboFunctions.Items.Insert(0, "-Please select a part function-");
This gives me a error. The whole idea is to have a combobox item that is kind of like a dummy item just saying something like "-Please select-"
|
|
|
|
|
Etienne_123 wrote: This gives me a error
And the error is...?
Etienne_123 wrote: adding a new item
I would think that you would add the new item to dv since that is what your itemssource is bound to.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Hello could any body help me, i need to record the live stream coming from ip devices into a video file. I have looked online for various sdks, but not much luck, i need to do this in c#. Any help would be apriciated. Many thanks
|
|
|
|
|
Hi people
I have a TextBlock that displays a calculated cost. The cost is stored in a double, and then I set TextBlock.Text to the cost.ToString(). What I want to know is, how do I convert this double value so that it displays only 2 decimal points e.g 56.99. Because at the moment it displays something like the following: 56.9999999999.
|
|
|
|
|
cost.ToString("N2");
have a look at this[^]
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
string ss = cost.ToString("N");
Have fun.
var question = (_2b || !(_2b));
|
|
|
|
|
Etienne_123 wrote: displays only 2 decimal points e.g 56.99.
you probably mean two fractional digits, a real number only has one decimal point.
x.ToString("F2") would work for me; how about looking at the documentation?
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Nevermind I figured it out.
I used:
double costTwoDecimals = Math.Round(costTotal, 2);
|
|
|
|
|
Etienne_123 wrote: Nevermind I figured it out.
I used:
double costTwoDecimals = Math.Round(costTotal, 2);
...That's not what you asked for. if you pass that function 56.9999999999 you will get 57 not 56.99 like you said you wanted.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
As far as I know, the framework doesn't provide this explicitly. However, if you really must return a truncated string, then I've whipped up an extension method for you:
public static string ToDecimalPlace(this double i, int decimalPlaces)
{
string toString = i.ToString();
int decimalPoint = 0;
if ((i % 1) == 0)
return toString;
decimalPoint = toString.IndexOf('.');
return toString.Substring(0, decimalPoint + decimalPlaces + 1);
}
I'm personally a little concerned about the strings being created, but I can't see a simple way around that problem. It will only usually show up under high load anyway. And remember to vet the input - this is only a proof of concept. If you do something like (8.1111111111111111111111111).ToDecimalPlace(840) you'll get an IndexOutOfRange exception.
|
|
|
|
|
Computafreak wrote: As far as I know, the framework doesn't provide this explicitly
double.ToString("F2")
|
|
|
|
|
I've seen that. But when I declare a simple double variable, with a value identical to that of the OP, then call ToString("F2") , I simply get 57.00. It seems to round instead of truncate.
|
|
|
|
|
Similar to the Computafreak solution, use an extension method:
public static double Truncate(this double d, int places)
{
double pow = Math.Pow(10, places);
return Math.Truncate(d * pow) / pow;
}
You can then use myDouble.Truncate(2).ToString() with any formatting you want.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Wow, that's clever. I hadn't thought of doing that - it'll be filed away for future use. That's actually a lot better than mine as well, because it doesn't use strings.
For the OP, what this function does is move the decimal place right by the number of places you want to get. Then it strips off the rest of the decimal places on that number, and moves the decimal place back again, so that everything stays the same. The sequence of events, assuming you want to convert 1.23456789 to 1.234 is this:
1.23456789 -> 1234.56789
Truncate -> 1234
Divide again -> 1.234
|
|
|
|