|
Hello Bill,
First of all thank you for your quick answer I wasn't expecting it, I have never ever got any answer from forums.
Yes everything is not born out of my brain, I took the basic idea and inspiration from
HERE
Using the Background worker is an idea, that I got idea while searching for ways to load images in async way.
Cache Manager concept was cleared by one of my cousin and I wrote my onw. but later on I fond one which was more better so used it.
And that's how I compiled all this, and that is the only reason I am not confident that what i did is right
Is the application fast enough under full load to satisfy you ?
No I am not.
Currently I tried loading 200 Images (each Image of around 6 MB) It takes around 1 Sec to Populate all the items in the Panel, and then around 10-15 secs to display all the Images on the items.
I was expecting it to do everything in less then sec, Am I expecting too much.
What specific questions, or concerns, do you have about your code ?
I wanted to know if there are any optimizations that I can do and I missed,
Also Since I am a newbie I am not pretty sure if I have done everything in correct way.
So as of now these are small questions I have.
Thanks
|
|
|
|
|
Member 8736475 wrote: Currently I tried loading 200 Images (each Image of around 6 MB) It takes around
1 Sec to Populate all the items in the Panel, and then around 10-15 secs to
display all the Images on the items. I was expecting it to do everything in
less then sec, Am I expecting too much.
So you want your HD to come up with 1.2GB worth of data in less than a second? Yeah, you're expecting too much, WAY too much.
To get the illusion of speed you have to cheat a bit. You load only the images you are displaying. If you're got 200 images in a folder, but can only show 10 on screen at a time, you only load the 10 that need to be loaded. The others can wait until either the user scrolls to see them or you can farm those off to a background thread to load.
|
|
|
|
|
Hi Dinesh,
As Dave commented, yes; you are expecting too much to load 1.2 gb. of pictures in under one second. I think even if you had the fastest SSD now available, and tons of RAM, etc., you wouldn't get that performance.
It's a very good practice to study advanced examples that stretch your mind, and challenge you, modify them, tweak them !
As Dave suggested, you probably want to look at "virtualization" if you want to optimize performance. The WinForms ListView Control supports virtualization via the 'VirtualMode Property: [^].
You can also put images in a ListView: [^].
I've never messed around with Images in a ListView, and have no idea how a ListView would perform using virtualization, with a lot of embedded images. Remember that the default .NET Controls are still "wrappers" around very old technology (COM/ActiveX).
Since you have a cache manager, I assume you are storing the thumbnails you generate in it (yes ?). If so, then if you consider (a guess) you are using something around 20k for one 128/144 thumbnail image, then 1200 images results in about 24 megabytes of storage. So, even if you "write-off" the one-time cost of generating the thumbnails, you are probably not going to be able to keep all of them in memory.
I'd consider using another method to contain the grid of images currently shown rather than FlowLayoutPanel, and suggest you substitute using PictureBox for inheriting from Button.
Wish I could be more helpful.
yours, Bill
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
|
|
|
|
|
Hello,
@Bill and @Dave thanks for bringing me to senses.
@Bill : You said you would consider using another method
Can you please guide me in this,
An Ideal common scenario in which this will be used is where there will be no more then 200 Files ( I hope )
And all the files will not be Images, there will be many different file types.
I considered using Control or Picturebox
But in this scenario I noticed that the Scrolling (Using mouse wheel doesnt work), Also the MouseEnter and MouseLeave events are not fired hence I shifted to Button.
Which control / what way do you suggest I substitute the FlowLayoutPanel with.
Thanks
Dinesh,
|
|
|
|
|
Is there a way to make a Form flashing in c#.
First idea is to use a timer changing form color. Is there a more elegant way?
Thanks for your time
|
|
|
|
|
|
Hi, PozzaVecia,
There are two main reasons you might want to make a Form/Window flash: one is to indicate an error message, or something urgently requiring the user's attention. In that case you want to bring the Form to the front, to make sure it's visible. The usual practice, in that case, is to put up a modal Form/Window, which will automatically appear as the frontmost window, and block your application.
You can define a Form, with whatever you want on it, and use FormX.ShowDialog() to display it modally. In many cases, however, the built-in MessageBox facility is all you need to use. Both these objects will automatically become the frontmost window when they are shown.
The second case is when you want to indicate to the end-user that you want them to bring a Form to the front, that's not in front now. But, it's hard for me to see a real reason for doing that:
1. if the Window is covered over by other Windows, the user won't see it change color, or Flash.
Using FlashWindowEx will not make the Window the active window, and bring it frontmost, although the Window will appear to have changed status visually, from inactive to active. MSDN docs for 'FlashWindowEx:
"It does not change the active state of the window."
"When a window flashes, it appears to change from inactive to active status. An inactive caption bar changes to an active caption bar; an active caption bar changes to an inactive caption bar."
In summary:
1. yes, you can make a Window flash, either by using the FlashWindowEx api that Dave K. referred you to, or by writing code, as you mentioned, using a Timer.
2. imho, you should use a modal Form/Window whenever you absolutely must get the end-user's attention, are willing to block the application, and require a response from the user.
3. in most cases, the built-in modal MessageBox facility will give you, for "free," a choice of buttons, default action button, icon, etc.
DialogResult result = MessageBox.Show("Core Melt Down Imminent" ,"Chernobyl Emergency Alert !",MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button3);
switch (result.ToString())
{
case "Ignore":
MessageBox.Show("Ignorance is life as usual.");
break;
case "Abort":
MessageBox.Show("To abort is impossible, sorry.");
break;
case "Retry":
MessageBox.Show("Trying again is a waste of time.");
break;
} There are some articles here on CP that may be useful to you: [^].
yours, Bill
“Humans are amphibians: half spirit, half animal; as spirits they belong to the eternal world; as animals they inhabit time. While their spirit can be directed to an eternal object, their bodies, passions, and imagination are in continual change, for to be in time, means to change. Their nearest approach to constancy is undulation: repeated return to a level from which they repeatedly fall back, a series of troughs and peaks.” C.S. Lewis
modified 18-May-13 10:10am.
|
|
|
|
|
very very useful!!!
thanks a lot
|
|
|
|
|
How can I read a the value of a column datatype Timestamp in my c# code?
I know that the timestamp is not a datetime in sql server.
I just want to read this to a byte array.
My code so far:
I have tried 3 variations and none of them even compile.
var myTimestamp = (byte)dr["TimeStamp"].ToString();
var myTimestamp = dr["TimeStamp"].ToString() as byte[];
var myTimestamp = dr["TimeStamp"].ToString();
I have googled and am unable to find it.
Pendin Approval
|
|
|
|
|
Maybe try System.Byte[] myTimestamp = (System.Byte[]) dr["TimeStamp"] ;
|
|
|
|
|
PIEBALDconsult wrote:
Maybe try
System.Byte[] myTimestamp = <br />
(System.Byte[]) dr["TimeStamp"] ;
Thank You. This has now been resolved.
Pendin Approval
|
|
|
|
|
Try reading it as a long.
|
|
|
|
|
That ain't gonna fly. (Unless maybe he casts it on the database side first.)
|
|
|
|
|
Hi to all.
I have a strange behaviour in a MDI project. I created a toolstrip with buttons in MDI parent for common operations in all children forms (New, Save and Delete).
In a child form, I have a DataGridView with a CheckBoxColumn and a TextBoxColumn with a list of options to choose by user. If i check some checkbox and I press the Save button in the toolstrip, I can't save any data: all the checkbox returns false value. But if i put a button in the child form and call the same void, all work very well.
Someone can answer why?
Here the code for button in MDI parent:
private void tsbtnSave_Click(object sender, EventArgs e)
{
if (this.ActiveMdiChild is Basic.AnalyzersCylinders) ((Basic.AnalyzersCylinders)this.ActiveMdiChild).Save();
}
Here the code to read the results:
public void Save()
{
foreach (DataGridViewRow dgRow in dgvAnalyzers.Rows)
{
if (dgRow.Cells["CheckedItem"].Value != null)
{
if ((bool)dgRow.Cells["CheckedItem"].Value)
{
}
else
{
}
}
}
}
And, obviously, the code for the button in Child form call the same Save() void.
|
|
|
|
|
If you put a breakpoint in the save routine and execute your application does it go to debug when you click on the save button?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Yes. In the save routine I see the checkedbox items values... but when I press the button in MDI parent, this values are always false, if I press the button in the child form, the values passes in the correct way.
|
|
|
|
|
Hello
Is there a way to extract some values from an XML node using the XmlPathNavigator ?
I need to extrat information from a XML file. I was first trying to use an XmlTextReader but the pure sequential access seeme a bit tedious to handle
So I was trying to use the XpathDocument
I use a XPathNavigator to browse each node of my document (see code below)
But for each product I just need to extract a few information
- Brand
- Model
- ID
(there are a lot of other unneeded information)
Is it possible to do that with the XpathNavigator ?
Or do I need another approach ?
Obviously I can write my own parser but I can't believe that there is no simple way with standard classes ?
Thanks for any help !
XPathDocument xmldoc = new XPathDocument(p);
XPathNavigator nav = xmldoc.CreateNavigator();
int j = 0;
foreach (XPathNavigator product in nav.Select("liste/mobile"))
{
j++;
}
|
|
|
|
|
Probably, but I've never used one. I use an XmlDocument; the SelectNodes and SelectSingleNode methods use XPath.
|
|
|
|
|
Thanks
I finaly found some solution
The first think to care is also the granularity
In my case every product embed a bloc_im node that contains everything
So the first select must be on "liste/product/bloc_im"
I was first doing "liste/product" and it take me a while to understand that first issue !
foreach (XPathNavigator product in nav.Select("liste/product/bloc_im"))
{
string refORF = product.SelectSingleNode("ref").Value;
string IdORF = product.SelectSingleNode("id").Value;
string Brand= product.SelectSingleNode("Brand").Value;
string modele = product.SelectSingleNode("model").Value;
sw.WriteLine("{0}\t{1}\t{2}\t{3}",Id,ref,Brand,modele);
XPathNavigator xNav = product.SelectSingleNode("TACS");
foreach (XPathNavigator xNav1 in xNav.Select("TAC"))
{
string Tac = xNav1.Value;
}
j++;
}
|
|
|
|
|
xmlDoc.SelectSingleNode(liste/mobile); should give the same results.
|
|
|
|
|
I've just discovered LINQ to XML, which makes processing XML files very easy.
You only need two classes (which become available when you have using System.Xml.Linq): XDocument and XElement.
XDocument opens the XML file. XElement is the type of each node in the XML tree. Some of the XElement methods return a nice IEnumerable list that you can process with foreach.
There's a lot more to LINQ to XML, but just these two classes enable you to easily do basic processing.
|
|
|
|
|
I'm not sure WCF is the way I should go here but I'm keen to get to learn a new technology so I thought I should investigate it at least.
We are developing a system in which we need a server-side application (with GUI, so not a Windows service) and several client side applications that communicate with this server side application. All of this happens on the internal network so I figured that TCP binding might be suitable.
The one approach would be to write some TCP/IP server routines on the server-side application and have the clients communicate with it over TCP sockets for which we'd have to implement certain messaging. What I dislike about this approach is the fact that all comms will be request-response type. In other words, the server can only send messages to the client if the client sent a message to the server.
So the possibility of full-duplex comms of WCF seems like a perfect solution. The thing I'm unsure of is whether WCF would allow for a server-side application that has a GUI and allows for user interaction.
I thought I might try getting to know WCF first by writing a small mini system, the sandwich lady notification system, consisting of a "server" side application which runs on the receptionist's computer. A number of other computers in the office then has a client application. The client application can send a message to the server application to subscribe itself to the notifications. When the sandwich lady arrives the receptionist can then open the GUI of the application on her machine and click a button which triggers the app to send a message to all the clients that has subscribed which in turn pops up a notification on the client machine.
I realise there might be better ways to achieve this particular solution but it is a reasonable analogy of what we ultimately want to achieve with out bigger system so I figure I might gain the skills I need if I can figure out how to write this little system.
My question is, could someone tell me please whether WCF is indeed the technology that should be used for this? I have only just started reading up on it but I am getting the impression that with WCF, the server side application will have to take the form of a service, not a desktop application. Could anyone give me some clarity on this please and possibly point me in the right direction for what I'm trying to achieve?
TIA
|
|
|
|
|
You might get a better response by posting your question in the WCF forum[^].
Use the best guess
|
|
|
|
|
Goodness! I didn't even notice there was a forum dedicated to WCF. Thanks for pointing out.
|
|
|
|
|
Hello,
I've just started to programm in C++, using Builder C++. I need to stablish comunication via internet between two computers. I've succed using the ClientSocket Component and the ClientServer but only if the computers are in a local network but not if the computers are in different networks. Here is my code for the server:
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::BAbrirClick(TObject *Sender)
{
ServerSocket1->Port=StrToInt(Npuerto->Text);
ServerSocket1->Open();
BAbrir->Enabled=false;
BCerrar->Enabled=true;
BEstado->SimpleText="Servidor Conectado!";
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
BEnviar->Enabled = true;
}
void __fastcall TForm1::BCerrarClick(TObject *Sender)
{
ServerSocket1->Close();
BAbrir->Enabled=true;
BCerrar->Enabled=false;
BEstado->SimpleText="Servidor Cerrado!";
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
BEnviar->Enabled = false;
}
void __fastcall TForm1::ServerSocket1ClientConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
BEstado->SimpleText="Conectado desde "+Socket->RemoteAddress;
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
}
void __fastcall TForm1::ServerSocket1ClientDisconnect(TObject *Sender,
TCustomWinSocket *Socket)
{
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections-1);
BEstado->SimpleText="Desconectado de "+Socket->RemoteAddress;
}
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
char * buffer;
int len;
AnsiString Mensaje;
int i;
int *tam;
tam = new int;
*tam = Socket->ReceiveLength();
len=Socket->ReceiveBuf(buffer,*tam);
buffer[len]=0;
TTime hora = TTime::CurrentTime();
AnsiString MensajeIn = Socket->RemoteAddress;
MensajeIn += " A las " + TimeToStr(hora) + " Dice" "----->";
ChatBox->Lines->Add(MensajeIn +StrPas(buffer));
BEstado->SimpleText=IntToStr(len)+"Nuevo mensaje entrante!";
Mensaje = StrPas(buffer);
strcpy(buffer,Mensaje.c_str());
for(i=0;i<ServerSocket1->Socket->ActiveConnections;i++)
ServerSocket1->Socket->Connections[i]->SendBuf(buffer,strlen(buffer));
delete[] buffer;
}
void __fastcall TForm1::BEnviarClick(TObject *Sender)
{
char buffer[256];
int i;
AnsiString Mensaje = CampoMensaje->Text;
strcpy(buffer,Mensaje.c_str());
for(i=0;i<ServerSocket1->Socket->ActiveConnections;i++)
ServerSocket1->Socket->Connections[i]->SendBuf(buffer,strlen(buffer));
TTime hora = TTime::CurrentTime();
ChatBox->Lines->Add("Servidor a las " +TimeToStr(hora)
+ " dice----->" + Mensaje);
}
void __fastcall TForm1::LimpiarClick(TObject *Sender)
{
ChatBox->Clear();
}
void __fastcall TForm1::CampoMensajeKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == 13)
TForm1::BEnviarClick(CampoMensaje);
}
void __fastcall TForm1::NpuertoKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == 13)
TForm1::BAbrirClick(Npuerto);
}
void __fastcall TForm1::TcpServer1Accept(TObject *Sender,
TCustomIpClient *ClientSocket)
{
TcpServer1->RemotePort = StrToInt(Npuerto->Text);
TcpServer1->Open();
BAbrir->Enabled=false;
BCerrar->Enabled=true;
BEstado->SimpleText="Servidor Conectado!";
NOnline->Text=IntToStr(ServerSocket1->Socket->ActiveConnections);
BEnviar->Enabled = true;
}
void __fastcall TForm1::TcpServer1CreateHandle(TObject *Sender)
{
NOnline->Text=IntToStr(TcpServer1->Active-1);
BEstado->SimpleText="Desconectado de "+TcpServer1->LocalHostName();
}
How can I implement comunication (a simple chat is enough) between the two computers?
|
|
|
|
|