|
I am playing with a program where I will need to have random image/images populated in either picture boxes or labels
I know how to create random numbers with the random next function but for the life of me I can NOT figure out how to create random images
I have all my images in three different imagelist (separated by category)
I have been looking online for tutorials but I am coming up empty handed…
Thank you for your time
|
|
|
|
|
you can
Try this[^]
this is asp.net example, you can use this concept in windows application also.
cheers,
Abhijit
|
|
|
|
|
A Customer can have multiple Products and a Product can be assigned to zero to more Customers
But, there are some items (such as BasePrice and DefaultPrefix) that are implicit to a customer-product relationship.
In the database this can be modeled as
Table Customer with Columns CustomerId, Name, etc.
Table Product with Columns ProductId, Name, etc.
Table CustomerProduct with Columns CustomerId, ProductId, BasePrice, DefaultPrefix, etc.
How would you model this as Domain Objects?
All I could think of is
Customer
..CustomerId
..Name
..AssignedProduct[] Products
Product
..ProductId
..Name
..Customer[] Customers
AssignedProduct : Product
..Customer Customer
..BasePrice
..DefaultPrefix
But that doesn't strike me as too slick (an Assigned Product has a Customer and a Customers[]???) and as this simplified example gets closer to what I actually have to model, this design starts to have problems among which is that NHibernate can't model some of this stuff
|
|
|
|
|
Hi.
Do you really need the customer relation in the product object?
If your app has a customer point of view, my suggestion would be:
Customer
..CustomerId
..Name
..AssignedProduct[] Products
Product
..ProductId
..Name
AssignedProduct : Product
..BasePrice
..DefaultPrefix
Kjetil
|
|
|
|
|
The short answer is no, multiple Customers can have instances of the same product (though in this case, different AssignedProduct) so it should be possible to navigate from Product to all Customers that are assigned it. Also, I've tried that set-up already and it has some more esoteric disadvantages.
The long answer is that this is a simplification of slightly more complicated schema. Basically, imagine the relations between Location, Customer, Product, and Container for a company which has multiple Locations at which it rents out Containers for Customers to store Product in. A Customer can exist at multiple Locations and a Location can have multiple customers (again, the existance of a relation entails additional data); a Customer can have mutliple Products and a Product can be assigned to multiple Customers - which have to be at a location to have a product assigned. Finally, each Product that is assigned to a customer can be stored in zero or more Containers.
The database in the meantime is not completely normalized, and since it is legacy, I cannot change it. It looks something like this:
Location
Customer
Product
Container
CustomerLocation with fk to Location, Customer
ProductCustomer with fk to Product, CustomerLocation
ContainerProduct with fk to Container, ProductCustomer
So, in addition to the set-up I postulated being a little awkward, it is actually currently impossible for me to map with NHibernate.
|
|
|
|
|
|
Wow...........................
But this site is only asking your programming related questions not your personal problems,search job portal.
|
|
|
|
|
Their is a reason by jobs.codeproject.com was invented
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Hi,
I have a sql server + c# windows + Crystal Report application.
I have write and reading(reports) procedures on the application.
About the reading procedures, i thinking on displaying my reports on forms and use the crytal report only if user meent/wants to print a report!!!
What do you think, what is the most likely way to display a report?
nelsonpaixao@yahoo.com.br
|
|
|
|
|
From what I've read so far, it's supposedly impossible to inline MSIL in C#, the compiler just doesn't allow it. I thought I'd see what y'all had to say about it anyway...
I have a DLL project in C#, and a couple of one-line functions are a bit of a bottleneck right now. In C#, they look like
int bar()(
return x & 0x7FFFFFFF;
}
bool foo(){
return bar() == 0;
}
Looking at the MSIL, there's a bit of a performance boost I can get back changing the .maxstack value from 8 to 2 for both of these functions. My results of using optimized vs. unoptimized code are similar to the results this guy got:
http://bytes.com/forum/thread227229.html[^]
With .maxstack 8, there are a few extra stack pushes/pops, and registers are zeroed out and then moved, and moved again, and these things really don't seem to accomplish much at all. Changing to .maxstack 2 and reassembling removes these extra instructions, and there's a definite performance boost (maybe 25%). Overall the function is quick, but it gets called so many times that I'd like to improve it's performance any way I can. With the problem I'm working on right now, it's already taking 2 hours to process a common set of data. I'd like to get it down to 1 hour, but I'll settle for 1.5.
I can disassemble the DLL, change the IL, and reassemble it if absolutely necessary, but I'd have to do this anytime to recompile the DLL. I'd like to just inline the MSIL changes I need to make rather than reassemble the DLL every time. Is this even possible?
Thanks,
Dybs
|
|
|
|
|
Do you really have to have the methods in a separate dll? If you would put them in the assembly where you use them, the compiler should just inline them, and there wouldn't even be a method call...
Also, I'm not sure that you are looking in the right place to find optimisations... What is it really that makes the job take so long time?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
The DLL is part of the PowerCollections, and when we ran our code through a profiler ((ANTS Profiler from Red Gate)[^], the most time our code spent by far was in the Set.UnionWith() function (defined in the PowerCollections DLL). Since we have the source code for the DLL, we profiled that as well, and ultimately most of the time was being spent in checking if a particular bucket in the Set was empty or not (for handling collision). These 2 functions are essentially those I described in my original post. The problem really is that we call UnionWith() so many times in this particular feature of our code. We've limited the number of calls about as must as we can, we just have so much data that the customer needs us to analyze. I'd prefer not to get into too many more details since this is for work.
Regarding assemblies, I've done some reading on them but I still don't really understand how to use them, (i.e. put a method in an assembly). We actually wrote the same 2 functions in C++ and C#, with the same compiler optimization settings and compared the IL, and the C++ IL already had the changes we wanted to make to the C# IL, so we're assuming (is that a bad thing? ) the C++ and C# compilers just produce different IL for the essentially the same code.
Is there a chance we're misinterpreting what the profiler is telling us about our bottleneck? Again, we've tried reducing the number of calls as much as we can (it's essentially a dynamic programming problem, and we've managed to cache our results as much as memory allows - depending on our data set, our final results may take up around 5 GB.) I realize I haven't posted any code yet, but I'd appreciate any suggestions you may have on optimizing this, if inlining the IL isn't the right approach.
Thanks,
Dybs
|
|
|
|
|
The JIT can & will inline methods. It won't inline them if you have a debugger or a profiler attached (including starting in release mode). (Unless you specifically configure your profiler to allow method inlining - I know Jetbrains dotTrace can do this).
|
|
|
|
|
dybs wrote: the most time our code spent by far was in the Set.UnionWith() function
I guess they do not know how to implement a Set with O(1) lookups, else UnionWith should be a O(n) operation. Like the other poster, I would rather question why you are being forced to use that function so much. Try write a simpler version.
|
|
|
|
|
Honestly, I think the root of the problem is just the amount of data we have - (some constant)^n, depending on the range of values the user specifies in the data set. We would need to consider all possible combinations of values for up to 10 items, and each item can range between 0 and 25. Right now we're focusing on just 5 items, all possible combinations, which already gives us nearly 10 million combinations. Ideally, I'd rather just reduce the data set, but that's not really an option at the moment.
dybs wrote: we profiled that (the Collections DLL) as well, and ultimately most of the time was being spent in checking if a particular bucket in the Set was empty or not (for handling collision).
As for how the Set is implemented, the problem with UnionWith() is the number of times it performs the above operations.
So for each of these combinations, we call UnionWith() for each item. So with 5 items, each ranging 0-25, we potentially call UnionWith 48 million times. As mentioned above, we've reduced the number of calls significantly by caching our results as we are able to, so we only call UnionWith() for the items that have changed since the last combination we tried. We're not sure how much simpler we can make it. I'd gladly take any suggestions. Not looking for anyone to do the work for me, just general ideas on this.
Thanks,
Dybs
|
|
|
|
|
I am writing some utility code that will need to operate in both web applications and windows applications and sometimes require different behaviours (such as where to retrieve config information from).
What is the best way for code to determine whether or not it is running as part of a Web application or part of a Windows application?
|
|
|
|
|
Methinks this should do it:
bool InWebApp()
{
return (HttpContext.Current != null);
}
/ravi
|
|
|
|
|
Thanks but HttpContext seems to only be defined in the context of a web page. I'm looking to make this determination in a static class.
|
|
|
|
|
Create a property in your Utility class and use it to determine from which type of App it was called from.
None the less, you will have to set the value of thsi property from you app
|
|
|
|
|
Having done a few more experiments, I think either
AppDomain.CurrentDomain.FriendlyName.Contains("vshost.exe");
-windows app seems to have vshost.exe in that string, web apps have a guid
or
rc = AppDomain.CurrentDomain.DomainManager == null;
-windows apps have a domain manager, for web apps it seems to be null.
Guess I will go with one of these until it fails.
|
|
|
|
|
k666 wrote: AppDomain.CurrentDomain.FriendlyName.Contains("vshost.exe");
This wont work. This is due the fact that you are running you win app from visual studio.
k666 wrote: rc = AppDomain.CurrentDomain.DomainManager == null;
Even this wont work This may or may not be true depending upon the case.
Try using my previous reply.
|
|
|
|
|
Your reply essentials says set a flag from code. I would prefer that the determination be automatic and how would I ensure that the flag gets set before it is ever used?
|
|
|
|
|
The other thing you could do is to check the Uri object.
In web, it should return you the address from where it was called else I suppose it would be null or could throw an exception.
|
|
|
|
|
Uri is a class.
I don't see any static properties/routines that fit the ticket and new Uri() works fine in windows apps if I give it a valid address.
|
|
|
|
|
Hi,
I am refreshing a page every 3 min. for data update using:
this.Response.AppendHeader("Refresh", "180");
in the Page_Load event.
If no activity is detected the page should timeout forcing users to login again. The timeout is set for 20 mim. that never happens because of the 3 min refresh time.
How can I achieve both the auto refresh and timeout?
Thanks for your time
PS: this.Page.Session.Timeout - does not work???? or does it? if so how?
|
|
|
|
|