|
Common solutions are:
1. Array of bools or a bool property on each thread controlling object (only if you need to know which threads are still running).
2. Static counter that gets incremented when each thread finishes.
3. Thread.Join each thread.
4. Use a synchronization object, e.g., an ManualResetEvent (my favorite).
Whatever solution you chose, don't forget to put robust exception handling, or your program will wait forever in case of an exception.
Yes, even I am blogging now!
|
|
|
|
|
Hi! I want to make NB shared folders scanner on C#.
How should I do this? Using netapi32.dll or perhaps, you could propose better choise??
PS: I'm sorry 4 my English$)
|
|
|
|
|
Start by enumerating the servers and workstations on the network using the NetServerEnum API exported by netapi32.dll. For each machine, enumerate its shares using the NetShareEnum API.
An example of using NetServerEnum can be found here[^].
See the Platform SDK for both NetServerEnum and NetShareEnum documentation at http://msdn.microsoft.com/library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
How i can fire(run) an event on a DataGrid cell?
|
|
|
|
|
It depends on the type of cell...if it's just a normal text box, then you can handle the event on the textbox itself...
|
|
|
|
|
How do you get the CurrentCell's text box from the data grid?
Greg Bayard
|
|
|
|
|
I use DataGridTimePickerColumn(class in msdn) style DataGrid column, when I edit grid cell ,it work well ,but when i insert new row,it has error of data convert,how i do?
|
|
|
|
|
More than likely (since you didn't give any details about the exception being thrown to you) need to define a default value for the column that you use the DataGridTimePickerColumn class. The value it displays - a DateTime - is a value type and cannot be null. You could optionally check for DBNull.Value in your code (modify the example: it's only an example anyway) and either assign a default value then or handle it however you want.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot!
this my code
DataGridTimePickerColumn tpcsCreatedDate = new DataGridTimePickerColumn();
tpcsCreatedDate.MappingName = "CreatedDate";
tpcsCreatedDate.HeaderText = "CreatedDate";
tpcsCreatedDate.NullText = DateTime.Now.ToShortDateString();
myGridStyle.GridColumnStyles.Add(tpcsCreatedDate);
this is DataGridTimePickerColumn from msdn
using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
// This example shows how to create your own column style that
// hosts a control, in this case, a DateTimePicker.
public class DataGridTimePickerColumn : DataGridColumnStyle
{
private DateTimePicker myDateTimePicker = new DateTimePicker();
// The isEditing field tracks whether or not the user is
// editing data with the hosted control.
private bool isEditing;
public DataGridTimePickerColumn() : base()
{
myDateTimePicker.Visible = false;
}
protected override void Abort(int rowNum)
{
isEditing = false;
myDateTimePicker.ValueChanged -=
new EventHandler(TimePickerValueChanged);
Invalidate();
}
protected override bool Commit
(CurrencyManager dataSource, int rowNum)
{
myDateTimePicker.Bounds = Rectangle.Empty;
myDateTimePicker.ValueChanged -=
new EventHandler(TimePickerValueChanged);
if (!isEditing)
return true;
isEditing = false;
try
{
DateTime value = myDateTimePicker.Value;
SetColumnValueAtRow(dataSource, rowNum, value);
}
catch (Exception)
{
Abort(rowNum);
return false;
}
Invalidate();
return true;
}
protected override void Edit(
CurrencyManager source,
int rowNum,
Rectangle bounds,
bool readOnly,
string instantText,
bool cellIsVisible)
{
DateTime value = (DateTime)
GetColumnValueAtRow(source, rowNum);
if (cellIsVisible)
{
myDateTimePicker.Bounds = new Rectangle
(bounds.X + 2, bounds.Y + 2,
bounds.Width - 4, bounds.Height - 4);
myDateTimePicker.Value = value;
myDateTimePicker.Visible = true;
myDateTimePicker.ValueChanged +=
new EventHandler(TimePickerValueChanged);
}
else
{
myDateTimePicker.Value = value;
myDateTimePicker.Visible = false;
}
if (myDateTimePicker.Visible)
DataGridTableStyle.DataGrid.Invalidate(bounds);
}
protected override Size GetPreferredSize(
Graphics g,
object value)
{
return new Size(100, myDateTimePicker.PreferredHeight + 4);
}
protected override int GetMinimumHeight()
{
return myDateTimePicker.PreferredHeight + 4;
}
protected override int GetPreferredHeight(Graphics g,
object value)
{
return myDateTimePicker.PreferredHeight + 4;
}
protected override void Paint(Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum)
{
Paint(g, bounds, source, rowNum, false);
}
protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
bool alignToRight)
{
Paint(
g,bounds,
source,
rowNum,
Brushes.Red,
Brushes.Blue,
alignToRight);
}
protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
Brush backBrush,
Brush foreBrush,
bool alignToRight)
{
DateTime date = (DateTime)
GetColumnValueAtRow(source, rowNum);
Rectangle rect = bounds;
g.FillRectangle(backBrush,rect);
rect.Offset(0, 2);
rect.Height -= 2;
g.DrawString(date.ToString("d"),
this.DataGridTableStyle.DataGrid.Font,
foreBrush, rect);
}
protected override void SetDataGridInColumn(DataGrid value)
{
base.SetDataGridInColumn(value);
if (myDateTimePicker.Parent != null)
{
myDateTimePicker.Parent.Controls.Remove
(myDateTimePicker);
}
if (value != null)
{
value.Controls.Add(myDateTimePicker);
}
}
private void TimePickerValueChanged(object sender, EventArgs e)
{
this.isEditing = true;
base.ColumnStartedEditing(myDateTimePicker);
}
}
please give me some more help!
|
|
|
|
|
I invoked the format command of OS(XP) in my code.But evry time it display a console window and I have to click the Enter key to go on the function. So,I wonder if there is a way to perform carriage return automatically and we do not need to click the Enter key?
Thanks for help!
|
|
|
|
|
|
Have you tried?
echo. | format a:
I don't know if it'll work, but give it a try. It's old DOS redirection, you are redirecting the ouput of the ECHO command (a carraige return) to the input of the FORMAT command.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi,
Sometimes the datagrid control is updating very slowly for some reason. In my program i have these circle objects and whenever the user clicks on one, the following occurs:
1. I create new DataRows for information contained in the circle clicked.
2. The rows are added to the DataTable bounded by the DataGrid.
3. When a different circle is clicked, the DataTable clears and the following steps are repeated.
The delay only seems to occur when a circle is clicked for the first time, each initial circle clicked on seems to update without a hitch.
Is this a cache issue? Thanks for the help!
Brian
|
|
|
|
|
Hello!
I´m new to C# and have a question for the pro's.
Is it possible to put an ArrayList into another ArrayList like a 2d array?
How would the code look like?
Regards.
stumpi
|
|
|
|
|
ArrayList list1 = new ArrayList();
ArrayList list2;
for (int i=0; i< 2 ;++i)
{
list2 = new ArrayList();
list2.Add(i);
list1.Add(list2);
}
|
|
|
|
|
Not sure if this is a stupid problem.
I have a C# ASP.NET app that is consuming web services from third party product.
Problem is this third party prog is using some odd formats for passing back certain types.
Examples
A bool value will return either “true” or <null>
A date/time stamp will have the letter “T” inserted in the string before the time component.
.NET’s default SOAP interpretation is having problem with these types and the third party product is kind of a black box.
Sticking in an override for handling of these types at the .NET end would be ideal, but I’m kind of shooting blind on where to start.
Has anyone run across an issue like this before?
WR
|
|
|
|
|
Have a look around the net/CodeProject/MSDN for information on SOAP Extensions. These allow you to do various things with SOAP packets before and after serialization and deserialization.
If you have, or can lay hands on "Developing XML Web Services and Server Components with Visual Basic .NET and Visual C# .NET" (ISBN 0-7356-1586-1) they are explained on page 446.
Failing that use these keywords:
AfterDeserialize
AfterSerialize
BeforeDeserialize
BeforeSerialize
SoapExtension
I realize this is only a push in the right direction, but it is a large-ish topic.
Cheers, Steve
|
|
|
|
|
How can i get all the relavant info from an MP3 file using C#?
like the ID3 tag and the other MPEG info?
And also how can i edit it?
VisionTec
|
|
|
|
|
This is not perfect but it works.
<br />
<br />
namespace id3 {<br />
<br />
using System;<br />
using System.IO;<br />
using System.Text;<br />
<br />
class FileCommands <br />
{<br />
<br />
public static void GetMP3Tag (ref MP3 paramMP3) <br />
{<br />
try<br />
{<br />
FileStream oFileStream;<br />
oFileStream = new FileStream(paramMP3.fileComplete , FileMode.Open);<br />
byte[] bBuffer = new byte[128];<br />
oFileStream.Seek(-128, SeekOrigin.End);<br />
oFileStream.Read(bBuffer,0, 128);<br />
oFileStream.Close();<br />
<br />
Encoding instEncoding = new ASCIIEncoding();
string id3Tag = instEncoding.GetString(bBuffer);<br />
<br />
<br />
<br />
if (id3Tag .Substring(0,3) == "TAG") <br />
{<br />
paramMP3.id3Title = id3Tag.Substring( 3, 30).Trim();<br />
paramMP3.id3Artist = id3Tag.Substring( 33, 30).Trim();<br />
paramMP3.id3Album = id3Tag.Substring( 63, 30).Trim();<br />
paramMP3.id3Year = id3Tag.Substring( 93, 4).Trim();<br />
paramMP3.id3Comment = id3Tag.Substring( 97,28).Trim();<br />
<br />
<br />
<br />
if (id3Tag[125]==0)<br />
paramMP3.id3TrackNumber = bBuffer[126];<br />
else<br />
paramMP3.id3TrackNumber = 0;<br />
<br />
paramMP3.id3Genre = bBuffer[127];<br />
paramMP3.hasID3Tag = true;<br />
}<br />
else <br />
{<br />
paramMP3.id3Title = paramMP3.fileFileName.Substring(0,paramMP3.fileFileName.LastIndexOf("."));<br />
paramMP3.id3Artist = "";<br />
paramMP3.id3Album = "";<br />
paramMP3.id3Year = "";<br />
paramMP3.id3Comment = "";<br />
paramMP3.id3TrackNumber = 0;<br />
paramMP3.id3Genre = 0;<br />
paramMP3.hasID3Tag = false;<br />
}<br />
}<br />
catch<br />
{<br />
paramMP3.id3Title = paramMP3.fileFileName.Substring(0,paramMP3.fileFileName.LastIndexOf("."));<br />
paramMP3.id3Artist = "";<br />
paramMP3.id3Album = "";<br />
paramMP3.id3Year = "";<br />
paramMP3.id3Comment = "";<br />
paramMP3.id3TrackNumber = 0;<br />
paramMP3.id3Genre = 0;<br />
paramMP3.hasID3Tag = false;<br />
}<br />
}<br />
<br />
public static void UpdateMP3Tag (ref MP3 paramMP3) {<br />
paramMP3.id3Title = paramMP3.id3Title.Trim();<br />
paramMP3.id3Artist = paramMP3.id3Artist.Trim();<br />
paramMP3.id3Album = paramMP3.id3Album.Trim();<br />
paramMP3.id3Year = paramMP3.id3Year.Trim();<br />
paramMP3.id3Comment = paramMP3.id3Comment.Trim();<br />
<br />
if (paramMP3.id3Title.Length > 30) paramMP3.id3Title = paramMP3.id3Title.Substring(0,30);<br />
if (paramMP3.id3Artist.Length > 30) paramMP3.id3Artist = paramMP3.id3Artist.Substring(0,30);<br />
if (paramMP3.id3Album.Length > 30) paramMP3.id3Album = paramMP3.id3Album.Substring(0,30);<br />
if (paramMP3.id3Year.Length > 4) paramMP3.id3Year = paramMP3.id3Year.Substring(0,4);<br />
if (paramMP3.id3Comment.Length > 28) paramMP3.id3Comment = paramMP3.id3Comment.Substring(0,28);<br />
<br />
byte[] tagByteArray = new byte[128];<br />
for ( int i = 0; i < tagByteArray.Length; i++ ) tagByteArray[i] = 0;
<br />
Encoding instEncoding = new ASCIIEncoding();
byte[] workingByteArray = instEncoding.GetBytes("TAG"); <br />
Array.Copy(workingByteArray, 0, tagByteArray, 0, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Title);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 3, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Artist);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 33, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Album);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 63, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Year);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 93, workingByteArray.Length);<br />
workingByteArray = instEncoding.GetBytes(paramMP3.id3Comment);<br />
Array.Copy(workingByteArray, 0, tagByteArray, 97, workingByteArray.Length);<br />
tagByteArray[126] = paramMP3.id3TrackNumber;<br />
tagByteArray[127] = paramMP3.id3Genre;<br />
<br />
FileStream oFileStream = new FileStream(paramMP3.fileComplete , FileMode.Open);<br />
if (paramMP3.hasID3Tag)<br />
oFileStream.Seek(-128, SeekOrigin.End);<br />
else<br />
oFileStream.Seek(0, SeekOrigin.End);<br />
oFileStream.Write(tagByteArray,0, 128);<br />
oFileStream.Close();<br />
paramMP3.hasID3Tag = true;<br />
}<br />
<br />
}<br />
<br />
struct MP3 <br />
{<br />
public string filePath;<br />
public string fileFileName;<br />
public string fileComplete;<br />
public bool hasID3Tag;<br />
public string id3Title;<br />
public string id3Artist;<br />
public string id3Album;<br />
public string id3Year;<br />
public string id3Comment;<br />
public byte id3TrackNumber;<br />
public byte id3Genre;<br />
<br />
public override string ToString()<br />
{<br />
return id3Title;<br />
}<br />
public MP3(string path, string name) <br />
{<br />
this.filePath = path;<br />
this.fileFileName = name;<br />
this.fileComplete = path + "\\" + name;<br />
this.hasID3Tag = false;<br />
this.id3Title = null;<br />
this.id3Artist = null;<br />
this.id3Album = null;<br />
this.id3Year = null;<br />
this.id3Comment = null;<br />
this.id3TrackNumber = 0;<br />
this.id3Genre = 0;<br />
}<br />
} <br />
}<br />
<br />
<br />
Leon v Wyk
|
|
|
|
|
This is a purely theoretical question--I'm not even asking for help this time.
I've been working a bunch with some clever datastructures and I have found myself needing to provide Equals overrides so that when I use Contains a correct comparison is used to determine whether elements are inside a datastructure.
Anyway, when you override Equals, you have to override GetHashCode. Why exactly is this? Is it that the default Equals behavior involves comparison of hash numbers for the objects being compared? I always thought that the default Equals was just comparison of addresses. Maybe it's my java experience bubbling over.
On this topic, if we do not know exactly how Microsoft/.NET's default implementation of GetHashCode operates, when we write our own implementations of GetHashCode isn't it possible that we could... well... really muck things up? It just seems like we would want the same hashing behavior for ANY kind of object.
vir·tu·al re·al·i·ty
n. Abbr. VR
A computer simulation of a real or imaginary universe in which Microsoft APIs are thoroughly documented and behave in an entirely logical manner.
|
|
|
|
|
McClamm wrote:
Anyway, when you override Equals, you have to override GetHashCode. Why exactly is this?
Two identical objects (x.Equals(y) == true) should return the same hashcode. If you fail to do it, you won't be able to use this object as a key on a Hashtable. Think about the string class: two different string instances, with identical chars, are equal (x.Equals(y) == true), and they return the same GetHashCode(), so they can be used as a key on a Hashtable.
Often, when you override Equals, you simply compare a field (or a combination of fields). Simply return the hashcode of this field, and probably you're done.
Yes, even I am blogging now!
|
|
|
|
|
I am a new programmer in C#, so I hope there is an easy answer for this problem.
I need to declare an array of class objects, and the code compiles fine, but I always get the runtime exception "Object reference not set to an instance of an object." When I single step through the code, the exception is thrown when the array declaration statement is executed. I have tried the same declaration, but for a single instance rather than an array, and it works fine. I can step through the constructor and see that all the variable are created properly.
Below are the two statements that I have used. I try the array declaration, and it bombs. The single instance works great. Any suggestions on what I am doing wrong? I can provide more details if needed.
Parameter[] yearsArray = new Parameter[yearsOfData];
Parameter yearArray = new Parameter();
Steve
|
|
|
|
|
Steve Searcy wrote:
Parameter[] yearsArray = new Parameter[yearsOfData];
This declares an array. All items on the array are null (yearsArray[0], yearsArray[1]... yearsArray[yearsOfData]).
You need to assign new instances to them in a loop.
Yes, even I am blogging now!
|
|
|
|
|
hi
how to control in a datagrid header .....
i mean want to add aheader to group of columns
suppose u have "First Name","Last Name" headers and u want to group them under a toal header "Personal Information" for example..
does any one kow how to do that !!??
|
|
|
|
|
Hi All,
With my datagrid I want different Column Headers to have different Colors?
There are global settings e.g
tableStyle.HeaderFont = Color.Green;
but I'm after soming like :
tableStyle.Columns[1].HeaderFont = Color.Green;
tableStyle.Columns[2].HeaderFont = Color.Blue;
I'm using C#. I'm aware of 3rd Party tools that can do this, but want to avoid them if possible.
Any help would be very much appreciated,
Thanks, Jonny
|
|
|
|
|