|
Opinion - you are heading for a disaster!
I don't know your data design but if you are pushing the limits of the container then you are doing something terrible wrong.
I NEVER return more than 1 table at a time from the database, very early on I once got 3 table in the same dataset and the response time was abysmal, getting 3 tables separately was dramatically faster.
I always use the HeirarchyID principle (but as a string not a HeirarchyID) /Parent/C1/C2/C3/C4/ your can then identify the position in the structure and the parentage of any element from the content of the heirarchyid.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I do not need to change the DB only how I distribute the data to the datasets on receiving. Currently I am constantly moving data in the DataTables. If I am able to delete a record and add another record at the end of the table this is much more efficient.
Furthermore, I found that if I transfer all my data to CSV files it is much faster than for storing and loading from a DB. I do not need a relational DB, I only need to store the data. Then load to my program when starting.
Michael
|
|
|
|
|
Hi,
Can you kindly shed some light on what's wrong with the below code?
Many thanks,
private Image DownloadImage(string _URL)
{
try
{
WebClient client = new WebClient();
Stream stream = client.OpenRead(_URL);
Image img = Image.FromStream(stream);
stream.Flush();
stream.Close();
return img;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
}
|
|
|
|
|
Muammar© wrote: The problem seems to be here
what problem?
Muammar© wrote: The problem seems to be here
looking at the full exception, not just its messge, would tell you exactly where it happens
|
|
|
|
|
Too little information - however, if you are getting a WebException , either your URL is not valid or there is some error while downloading data. Check that the URL you are passing is correct.
|
|
|
|
|
MessageBox.Show(e.Message);
what's message? if the _url is valid, open(_url)'ll back e.Message
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
WebClient wc = new WebClient();
wc.DownloadFileAsync(new Uri("http://www.xxxx.com/xx.gif"), "D:\\xx.gif");
wc.DownloadFileCompleted+=new AsyncCompletedEventHandler(wc_DownloadFileCompleted);
}
private void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("完成!");
}
|
|
|
|
|
Works like a charm
Thank you!
|
|
|
|
|
Ahem. You forgot to reallocate the reference to your event handler.
|
|
|
|
|
Did you check the OpenRead explanation on MSDN[^]?
ArgumentNullException
The address parameter is Nothing.
WebException
The URI formed by combining BaseAddress, address is invalid.
-or-
An error occurred while downloading data.
V.
|
|
|
|
|
I'm trying to refactor this messenger class so that it's generic, but I'm getting a compile error.
private Dictionary<Type, List<Action<object>>> internalList;
public void Register<T>(Action<T> callback)
{
Type messageType = typeof(T);
List<Action<T>> list;
if (internalList == null)
{
internalList = new Dictionary<Type, List<Action<object>>>();
}
if (!internalList.ContainsKey(messageType))
{
list = new List<Action<T>>();
internalList.Add(messageType, list);
}
else
{
list = internalList[messageType];
}
list.Add(callback);
}
It doesn't like either
internalList.Add(messageType, list);
or
list = internalList[messageType];
I don't understand why because the Dictionary is defined to accept a
List<Action<object>> . So the 2 lines above should work, right?
What am I doing wrong here?
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: I don't understand why because the Dictionary is defined to accept a
List<Action<object>> . So the 2 lines above should work,
right? What am I doing wrong here?
No. An object is not a T. Use T instead of object and it will work.
|
|
|
|
|
Except that you can't define
private Dictionary<Type, List<Action<object>>> internalList;
with a generic. So what's the right way to do this?
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: Except that you can't define
private Dictionary<Type, List<Action<object>>> internalList;
with a generic. So what's the right way to do this?
Yes, you can:
private Dictionary<Type, List<Action<T>>> _dict = new Dictionary<Type, List<Action<T>>>();
This has to be a member of the T class obviously. Does that dictionary exist somewhere else?
|
|
|
|
|
It's a private field on the class, so you can't define it with T unless the class itself is defined with T. But that's not what I'm looking for here.
Everything makes sense in someone's mind
|
|
|
|
|
It isn't? It sounds like you are trying to stick different types of T into the same dictionary. You can't. That's very wrong. The whole point of generics is that you have a strongly typed class of type T. If you could stick different types of T into the same dictionary, it wouldn't be strongly typed and how would the compiler know which type of T to do stuff on?
I'm thinking you are trying to refactor things in a way that don't make sense if you are trying to do that.
modified 27-Mar-12 12:42pm.
|
|
|
|
|
Just to second Sledgehammer's point, your main problem here is that you are trying to store a whole load of different Action<T> handlers (i.e. handlers for different object types) in the same list. If you think about how you'd try to actually read handlers back out of this list again (in order to fire them, for example) you'll realise that with your current design you can't possibly know which type of handler you have.
If you actually need a central registry of different handler types, I think you need to do something like
class MainStorageClass {
Dictionary<Type, BaseRegistry> registries;
public void Register<T>(Action<T> callback) {
Type messageType = typeof(T);
Registry<T> registry;
if (registries == null)
{
registries = new Dictionary<Type, BaseRegistry>();
}
if (!registries.ContainsKey(messageType))
{
registry = new Registry<T>();
internalList.Add(messageType, registry);
}
else
{
registry = internalList[messageType];
}
registry.Actions.Add(callback);
}
private abstract class BaseRegistry {}
private class Registry<T> : BaseRegistry {
internal List<Action<T>> Actions { get; private set; }
internal Registry() { Actions = new List<Action<T>>(); }
}
}
You could technically do it with Delegate as the base type for Action, but List<Delegate> doesn't superclass List<Action<T>>, so it's less ugly this way, I think. Note that BaseRegistry doesn't actually do anything apart from act as a superclass you can declare the dictionary as using; you could use Dictionary<Type, object> and it would work the same, but I think that is unclear and permits you to make bad mistakes.
And now you can look up like
public List<Action<T>> Find<T>(){
if(registries == null) return null;
BaseRegistry registry;
if(!registries.TryGetValue(typeof(T), out registry)) return null;
return (registry as Registry<T>).Actions;
}
... which I think is quite clean.
Edit: Changed Find slightly, I don't think the original would compile and you need a cast.
modified 27-Mar-12 11:28am.
|
|
|
|
|
So I've got these UpdatePanel(s):
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateButton2" eventname="Click" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" id="DateTimeLabel1" />
<asp:Button runat="server" id="UpdateButton1" onclick="UpdateButton_Click" text="Update" />
<asp:Label runat="server" id="statusSpan"/>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" id="UpdatePanel1" updatemode="Conditional">
<ContentTemplate>
<asp:Label runat="server" id="DateTimeLabel2" />
<asp:Button runat="server" id="UpdateButton2" onclick="UpdateButton_Click" text="Update" />
<asp:Label runat="server" id="statusSpan2"/>
</ContentTemplate>
</asp:UpdatePanel>
And I've got this code behind:
protected void UpdateButton_Click(object sender, EventArgs e)
{
DateTimeLabel1.Text = DateTime.Now.ToString();
DateTimeLabel2.Text = DateTime.Now.ToString();
statusSpan.Text="FIRED BY (blahblahblahbeeddy blah)";
}
As you can see (the 'blah blah blabbeddy bla' section), I'd like to somehow have the codebehind either catch, be aware of, or report back what Element fired or called the codebehind method. Is this possible?
|
|
|
|
|
cknight725 wrote: object sender
have you looked at the sender at all? apply GetType() or ToString() to it once, to discover what it is; when it is something you can handle, cast ir to its actual type and use it any way you like.
|
|
|
|
|
Thanks!! It was staring me right in the face probably for much longer than I'd care to admit. For completeness, and perhaps to help others out this is my solution:
protected void UpdateButton_Click(object sender, EventArgs e)
{
System.Web.UI.WebControls.DropDownList caller = (System.Web.UI.WebControls.DropDownList)sender;
string senderSrc=caller.ID.ToString();
if (senderSrc=="DropDown1")
{
{
else
{
}
}
|
|
|
|
|
You're welcome.
|
|
|
|
|
I'd like to query a 64bit OS with my 32bit OS and see how the 64bit OS actually stores bits or bytes.
Does the OS stuff 8 bytes into each double long, to a point that if you do not have a multiple of 8 with the number of bytes you need for your string, you have 1 or more empty bytes in the last double long? Are all strings just byte arrays with terminating 0's?
|
|
|
|
|
I'm no expert on this, but...
turbosupramk3 wrote: Are all strings just byte arrays with terminating 0's?
That's likely language/framework dependent. In .net, strings are not NULL-terminated (and may include NULLs).
turbosupramk3 wrote: stuff 8 bytes into each double long
I'm fairly sure that only applies to registers. Or when defining a structure.
Why do you ask? It probably shouldn't matter to everyday programming.
|
|
|
|
|
This isn't every day programming, I'm converting a 64 bit to a 32 bit D word
|
|
|
|
|
None of that made sense. What do you really want?
|
|
|
|