|
With Reflection. But it's not generally a good idea.
|
|
|
|
|
I'd like to use the asynchronous model with the Socket class to receive data.
The BeginReceive function must be told how many bytes you wish to receive:
public IAsyncResult BeginReceive(
byte[] buffer,
int offset,
int size,
SocketFlags socketFlags,
AsyncCallback callback,
Object state
)
Does this mean that if I pass size = 200 , and there are 199 bytes waiting for me, it won't complete the receive?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
If you read the sample supplied with the document of Socket.BeginReceive Method[^] you will notice that the size specified is the size of the buffer passed to the function. So this size has no relation with the amount of bytes waiting to be received.
In the callback function you determine if all the data has been received or whether there is any more data. If there is more data you call BeginReceive again.
So to answer your question directly when 199 bytes are waiting and you pass a buffer of 200 bytes the receive will complete.
If you had used a buffer of 100 bytes you would have needed to perform two receives to get all the bytes. This means that you would have to put the two receives together in a larger buffer.
I hope I clarified it for you.
0100000101101110011001000111001011101001
|
|
|
|
|
Thank you, that clears it up.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi All, I am trying to get in my gridView there are two template fields. I need to get those Rows[0] and Cell[0] value.
Please help.
"if you don't know ask"
|
|
|
|
|
object jashimusValue = dataGridView[0 , 0].Value; Didn't test it on the compiler though.
Bastard Programmer from Hell
|
|
|
|
|
Hello,
I have created small program with one button "OK" and
"DataGridVew1" with one column "Messages",
for storing text messages.
When I start the program , i enter some messages to "DataGridView1"
and when I click "OK Button" ,MessageBox shows with text of textmessage in first row.
For unswering to your question look this sample code:
void Button1Click(object sender, EventArgs e)
{
int row = 0;
int column = 0;
string message;
if (dataGridView1[column,row].Value == null)
{
dataGridView1[column,row].Value = "Empty";
}
message = dataGridView1[column,row].Value.ToString();
MessageBox.Show(message);
}
I think that the answer to your question is obvious.
All the best,
Peric Zeljko
periczeljkosmederevo@yahoo.com
modified 6-Oct-11 14:56pm.
|
|
|
|
|
Hi
How can you set/read file attributes, those under "Summary" tab when you right click a file in File Explorer? (i.e. NOT System.IO.FileAttributes[^])
I need to set things like Subject, Author, Category, Keywords, Comments
Thanks
dev
|
|
|
|
|
Are you talking about the ones provided by Office, or are you talking about custom ones? If it's Office, you can use dsofile[^] to read/write document properties. If you are talking about a custom format, you are going to have to do a lot more work - and work with things such as IPropertySetStorage[^].
|
|
|
|
|
I have several supporting classes that are all exactly the same except for one property, which is a List, something like this :-
public class DecimalClass
{
public int x;
public string y;
public List<decimal> Details;
}
public class StringClass
{
public int x;
public string y;
public List<string> Details;
}
Now in my main class I need to have several of these base classes , and so I thought of having one generic class like so :-
public class MyClass<T>
{
public int x;
public string y;
public List<T> Details;
}
and having a List<MyClass<T>> myClasses in my Main class, but this would mean the List would only be able to hold one Type, and I would need it to hold several different Types, the total number and Types of which would remain unknown until the class is created further down the line. If anyone can understand what I am trying to do, and can suggest a solution I would be more than grateful, as at the moment I am having to create a main class for each combination of sub classes that are required.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Hmmmm. Ultimately all classes derive from object , so you could store the data in a List<object>, but this wouldn't give you any advantage over storing as an ArrayList. This means you'd have a lot of boxing/unboxing to take care of, and you'd end up having to use reflection to work out what type to convert it back to.
Alternatively, you could store it in a Dictionary<Type, List<object>> and use that to avoid having to use the reflection part. Just a thought.
|
|
|
|
|
Hi Pete,
Thanks for your input. I think I will have to go with List<object> , but decided to pass the Type in as a parameter to the constructor for the sub class with a private Type variable, as it meant the least changes to existing code, though if I had to start from scratch again, I would have used the dictionary as you suggested. Thanks again for your time.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Make the base class
public class MyBaseClass
{
public int x;
public string y;
public IEnumerable Details;
} And derive the generic class from it.
public class MyClass<T> : MyBaseClass
{
public MyClass<T>()
{
Details = new List<T>();
}
} That way, you could hold a List<MyBaseClass> baseClassList in your Main class.
Ciao,
luker
|
|
|
|
|
Unfortunately, holding a List of MyBaseClass I would need to use reflection to cast from MyBaseClass to MyClass in the Main Class and so I would be back to where I started, as I need to know the Type of object I am dealing with. Thanks for your thoughts.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Don't cast. Use polymorphism instead.
Declare the methods you need in MyBaseClass and override them in MyClass<T> .
Calling baseClassList[0].SomeMethod() will cause the correct override to execute.
Ciao,
luker
|
|
|
|
|
I think you need to explain more thoroughly what you are actually trying to do. The list of 'lots of stuff' seems confused and that should almost certainly be a List<BaseClass> (or an interface, possibly) where BaseClass defines all the things that you want to do on the different MyClass types.
Similar to the answer above, I would factor out the common, non generic parts into a base class (note that this isn't necessarily the same BaseClass referenced in the first paragraph, though it could be; the question is not detailed enough to be able to tell):
public abstract class BaseClass {
public int x;
public string y;
public virtual IEnumerable BaseDetails { get; set; }
}
public class MyClass<T> : BaseClass {
public IList<T> Details { get; set; }
public override IEnumerable BaseDetails {
get { return Details; }
set { Details = (IList<T>)value; }
}
}
BaseClass should also define virtual methods for whatever operations you are going to want to do on things pulled out of the list.
|
|
|
|
|
Maybe this helps:
public class Test {
public void Run() {
List<MyBase> all=new List<MyBase>();
all.Add(new MyGeneric<int>());
all.Add(new MyGeneric<string>());
foreach(MyBase b in all) {
log("Holding a list of "+b.MyType);
}
}
public class MyBase {
public Type MyType;
public MyBase(Type type) {
MyType=type;
}
}
public class MyGeneric<T> : MyBase {
public int x;
public string y;
public List<T> Details;
public MyGeneric() : base(typeof(T)) {}
}
}
|
|
|
|
|
I would like to create a custom usercontrol with some custom drawing using TextBoxRenderer. All I get with TextBoxRenderer.DrawTextBox() and also with ComboBoxRenderer.DrawTextBox() are single solid gray rectangles not using Visual Styles. When I use ComboBoxRenderer.DrawDropDownButton() the drawing is perfectly using Visual Styles. The Application.EnableVisualStyles() is called in program.cs and TextBoxRenderer.IsSupported returns true. In the code below I added a textbox to show Visual Styles are on.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Drawing;
namespace WindowsFormsApplication1
{
public class UserControl2 : UserControl
{
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
this.BorderStyle = BorderStyle.FixedSingle;
TextBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(10, 10, 50, 50), TextBoxState.Normal);
TextBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(70, 10, 50, 50), TextBoxState.Hot);
ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(10, 70, 20, 20), ComboBoxState.Normal);
ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(70, 70, 20, 20), ComboBoxState.Hot);
TextBox tb = new TextBox();
tb.Location = new Point(10, 100);
this.Controls.Add(tb);
}
}
}
Using: Win7 Prof 64 bit, visual studio 2008, .net 3.5
Thanks in advance for any suggestions...
|
|
|
|
|
Have you checked the ...Renderer.IsSupported to see if visual styles are supported for you?
|
|
|
|
|
Yes... see text in my post. I removed these if's in my post to keep the listing a bit shorter, but this is what I have
if (TextBoxRenderer.IsSupported)
{
TextBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(10, 10, 50, 50), TextBoxState.Normal);
TextBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(70, 10, 50, 50), TextBoxState.Hot);
}
if (ComboBoxRenderer.IsSupported)
{
ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(10, 70, 20, 20), ComboBoxState.Normal);
ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(70, 70, 20, 20), ComboBoxState.Hot);
}
|
|
|
|
|
Hello Everybody,
I am using threading in my application. In which have there is a problem is occurred while executing the program for depth Algo.
if i am executing Thread for normal function then it works properly. if i execute the same thread for depth function there are generates the problem of Memory Usage and CPU usage. After that the application can't response and generate not enough memory error.
So please can u provide the help for controls the Thread if the memory is not available.
Thanks
If you can think then I Can.
|
|
|
|
|
Without the relevant code fragment, it isn't possible to answer that with absolute confidence, but I assume that your depth function is recursive, and that it is calling itself with the wrong parameters, causing it to loop on a node of some form.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I have created a desktop app for facebook.I even got api and secret key from facebook,but it doesnt work for other user.It works good for me but it doesnt allow other user to login into the app.Plz help me
|
|
|
|
|
facebook is evil dont support them your soul will be lost... i hope that is helped you my friend
|
|
|
|
|
Yeah I know brother,but there should be some way to do this
|
|
|
|
|