|
I have this method that accepts a ZipFile as a parameter and does some work etc, but after looping within a while loop, the parameter (ZipFile) is disposed... I will show a quick example instead of the original code because it would be unnecessarily complex.
private byte[] GetImage(ZipFile originalZipFile, string pass)
{
while(true)
{
ZipFile zipFile = originalZipFile
foreach(ZipEntry zEntry in zipFile)
{
if(true)
return new byte[];
}
}
}
I have attempted to keep the example simple enough.. So, zipFile is closed and set to null within the while loop, even before the return (else an exception occurs, since the ZipFile is using a FileStream which is later needed). However, originalZipFile is for some reason being disposed without any calling directly accessing it (that is why originalZipFile is copied into zipFile)
What can I do in order to keep originalZipFile from being disposed? Or what am I doing wrong? Thanks!
(As far as I am concerned, ZipFile is a class not a struct, so there shouldn't be any problems, with multiple references to the same 'object' on the stack).
|
|
|
|
|
If ZipFile is a class and not a struct, then you are not making a copy of originalZipFile when you assign it to zipFile, only a copy of the reference. So anything you do to zipFile is done to originalZipFile since they both reference the same object. If you intended to make a copy of originalZipFile, you will have to make and use a method that will create the copy.
|
|
|
|
|
Hi,
there is no Dispose() and no using construct in what you have shown, so nothing is getting disposed of as far as we can see.
If things go wrong, chances are you didn't understand how something works, hence it is quite possible that by simplifying the code to show it here, you also have hidden the problem.
Show exact code, omitting only the parts that are really irrelevant; but do show everything that happens to originalZipFile and any copies thereof.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
First of all I would like to thank you for taking the time to reply You really seem like you want to help So, I totally agree with you that by simplifying the code I might also be hiding the problem.
The program functions as follows. At every specified interval, the application extracts an image from a ZIP file according to "liked shoots" since this is based on a group of photographers each having their own shoots submitting, and so on...
The code in demand is a follows:
private byte[] GetShootImage(ZipFile originalZipFile, string pass, string shootName)
{
while (fm.LikedShoots.Count > 0)
{
ZipFile shootZipFile = originalZipFile;
ZipEntry zipEntry = shootZipFile.GetEntry(fm.LikedShoots[0]);
if (zipEntry != null)
{
TempSaveStream(shootZipFile.GetInputStream(zipEntry), zipEntry.Size, true);
zipEntry = null;
shootZipFile.Close();
shootZipFile = null;
shootZipFile = new ZipFile("C:\\WINDOWS\\Temp\\TpTmp\\temp.tmp");
shootZipFile.Password = pass;
foreach (ZipEntry entry in shootZipFile)
{
if (!fm.ImageGenerated(fm.LikedShoots[0] + "\\" + entry.Name))
{
fm.GeneratedPhotos.Add(fm.LikedShoots[0] + "\\" + entry.Name);
buffer = TempSaveStream(shootZipFile.GetInputStream(entry), entry.Size, false);
shootZipFile.Close();
shootZipFile = null;
return buffer;
}
}
}
fm.ExhaustedShoots.Add(fm.LikedShoots[0]);
fm.LikedShoots.RemoveAt(0);
}
}
On the 2nd loop, the marked line of code throws an ObjectDisposedException within the originalZipFile object. However, as you can see, originalZipFile is not set to null or anything. Can the GC have collected it or what?
In the mean, I would like to thank you so much for taking the time to reply.
|
|
|
|
|
Hi,
I haven't grasped the structure of your code yet; anyway this code too could use some cleaning up:
1. parameter shootName isn't used.
2. several xxx=null; don't make any sense.
3. as TempSaveStream() causes problems, one should look at its code.
Please make sure you have proper error/exception handling, as explained in our other conversation.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I'm posting just to let you know of a few 'updates'. I haven't changed the code yet, but I will soon enough, and I'll inform you then.
At the moment:
1. 'shootName' is used but not in that code extract. It's in the same method, but it's set in a if...else situation, which is irrelevant
2. I'm not sure if this is my misconception or anything, but I had rather thought that if an object is set to null, this makes GC more likely/quickly to occur on that object, to release the resources occupied by it? If this is my mistake, than I'm glad to know
3. I'll check TempSaveStream() again to ensure that it's not causing the problem.
Furthermore, I WILL check the exception handling, due to the embarrassing exception handling I've implemented in the other conversation we've had
Besides, I will check certain properties in the ZipFile class, since, for instance, there is a particular property that once the child's finished, it also closes the parent zip. So it may be something along those lines
Thanks for taking the time I'll keep you informed
|
|
|
|
|
suppose i have two table table1 & table2. now how can i sync the data of two table of sql server using microsoft sync frame work or using any other class.
tbhattacharjee
|
|
|
|
|
You can use "Instead Of" or "After" triggers on those tables for Insert, Update and Delete actions.
For example:
<br />
USE YourDatabase<br />
<br />
CREATE TRIGGER Table1_AfterDelete <br />
ON Table1 AFTER DELETE<br />
AS<br />
DELETE Table2 WHERE Table2.Id IN (SELECT Id FROM DELETED)<br />
GO<br />
<br />
CREATE TRIGGER Table1_AfterInsert <br />
ON Table1 AFTER INSERT<br />
AS<br />
INSERT INTO Table2 SELECT * FROM INSERTED<br />
GO<br />
<br />
CREATE TRIGGER Table1_AfterUpdate <br />
ON Table1 AFTER UPDATE<br />
AS<br />
UPDATE Table2<br />
SET Table2.FirstName=Table1.FirstName, Table2.LastName=Table1.LastName<br />
FROM Table2 JOIN Table1 ON Table2.Id=Table1.Id<br />
GO
|
|
|
|
|
While stonehearts answer is technically correct, I would question your data structure if you are storing the same data in 2 tables. I suggest you do some research into normalising your database (said with absolutely no knowledge of your data structure).
Besides triggers are EVIL and should be avoided unless they are essential.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
have create a dynamic menu but problem is that how we give for a page link in clildnodes.
my code is like that---------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class top : System.Web.UI.Page
{
SqlConnection conn;
DataUtility dut = new DataUtility();
protected void Page_Load(object sender, EventArgs e)
{
PopulateMenu();
}
private void PopulateMenu()
{
DataSet ds = GetDataSetForMenu();
Menu menu = new Menu();
menu.MenuItemClick += new MenuEventHandler(menu_MenuItemClick);
foreach (DataRow parentItem in ds.Tables[0].Rows)
{
MenuItem categoryItem = new MenuItem((string)parentItem["Catname"]);
menu.Items.Add(categoryItem);
foreach (DataRow childItem in parentItem.GetChildRows("Children"))
{
MenuItem childrenItem = new MenuItem((string)childItem["Subcatname"]);
categoryItem.ChildItems.Add(childrenItem);
}
}
Panel1.Controls.Add(menu);
Panel1.DataBind();
}
void menu_MenuItemClick(object sender, MenuEventArgs e)
{
string selected = e.Item.Text;
Response.Write(selected);
}
private DataSet GetDataSetForMenu()
{
conn = dut.getConnection();
SqlDataAdapter adCat = new SqlDataAdapter("SELECT tbl_Category.* FROM tbl_Category,tbl_Usercat where tbl_usercat.uid=1 and tbl_Category.sno=tbl_Usercat.catid", conn);
SqlDataAdapter adProd = new SqlDataAdapter("SELECT tbl_SubCategory.* FROM tbl_SubCategory,tbl_UserSubcat where tbl_UserSubcat.UID=1 and tbl_SubCategory.sno=tbl_UserSubcat.SubCatid", conn);
DataSet ds = new DataSet();
adCat.Fill(ds, "tbl_Category");
adProd.Fill(ds, "tbl_SubCategory");
ds.Relations.Add("Children", ds.Tables["tbl_Category"].Columns["sno"], ds.Tables["tbl_SubCategory"].Columns["CatID"]);
return ds;
}
}
so plz help me soon.
thanks
vivek
|
|
|
|
|
Why have you posted this more than once? Is it a blatant attempt to bump your post to the top? You must think we're idiots - by doing this, you pretty much guarantee that people aren't going to want to help you. There's an etiquette involved in the forums, and you've just disregarded it.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Never mind he posted in the wrong forum..
|
|
|
|
|
Hi,
There is a vertical ToolStrip in my application. ToolStrip buttons are dynamically added. When number of added control increases, all controls that overflows comes into a menu . Is there any way to add a scrollbar or scroll button into the toolstrip to avoid this overflow menu.
Thanks in Advance
|
|
|
|
|
You can use a panel.
1- Place a panel on your form and dock it for example to left
2- Set the AutoScroll Property of panel to True.
3- Place your Toolstrip in your panel.
4- Set the AutoSize Property of ToolStrip to True and LayoutStyle to VerticalStackWithOverflow Or Table or Flow.
|
|
|
|
|
have create a dynamic menu but problem is that how we give for a page link in clildnodes.
my code is like that---------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class top : System.Web.UI.Page
{
SqlConnection conn;
DataUtility dut = new DataUtility();
protected void Page_Load(object sender, EventArgs e)
{
PopulateMenu();
}
private void PopulateMenu()
{
DataSet ds = GetDataSetForMenu();
Menu menu = new Menu();
menu.MenuItemClick += new MenuEventHandler(menu_MenuItemClick);
foreach (DataRow parentItem in ds.Tables[0].Rows)
{
MenuItem categoryItem = new MenuItem((string)parentItem["Catname"]);
menu.Items.Add(categoryItem);
foreach (DataRow childItem in parentItem.GetChildRows("Children"))
{
MenuItem childrenItem = new MenuItem((string)childItem["Subcatname"]);
categoryItem.ChildItems.Add(childrenItem);
}
}
Panel1.Controls.Add(menu);
Panel1.DataBind();
}
void menu_MenuItemClick(object sender, MenuEventArgs e)
{
string selected = e.Item.Text;
Response.Write(selected);
}
private DataSet GetDataSetForMenu()
{
conn = dut.getConnection();
SqlDataAdapter adCat = new SqlDataAdapter("SELECT tbl_Category.* FROM tbl_Category,tbl_Usercat where tbl_usercat.uid=1 and tbl_Category.sno=tbl_Usercat.catid", conn);
SqlDataAdapter adProd = new SqlDataAdapter("SELECT tbl_SubCategory.* FROM tbl_SubCategory,tbl_UserSubcat where tbl_UserSubcat.UID=1 and tbl_SubCategory.sno=tbl_UserSubcat.SubCatid", conn);
DataSet ds = new DataSet();
adCat.Fill(ds, "tbl_Category");
adProd.Fill(ds, "tbl_SubCategory");
ds.Relations.Add("Children", ds.Tables["tbl_Category"].Columns["sno"], ds.Tables["tbl_SubCategory"].Columns["CatID"]);
return ds;
}
}
so plz help me soon.
thanks
vivek
|
|
|
|
|
Is there a way to open multiple pdf files, via c# please?
|
|
|
|
|
|
Hi.
Can I use RequireFieldValidator control to check for the blank data? There, both of the two textboxes must not be blank. But it'll be ok if only one of these two textbox must be entered data. If with RequireFieldValidator, how can I use with it?
Thanks.
|
|
|
|
|
Strictly speaking, this question should be in the ASP.NET forum, and no - a required field validator validates that a field is required, not that one of two fields is required. You'll need to write a custom validator.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
This is a repost; it's already posted in the .NET Framework forum. Please be patient and don't spam the forums with the same question.
You can check out the PictureBox [^], you could adapt that to suit your needs.
|
|
|
|
|
I wanna sample demo for streaming media player in C# on WinCE, does anybody has?
Or can anyone tell me how to do that?
|
|
|
|
|
Hello everyone
Please tell me how many positive value give the signed integer in sql
Thanx in advance
|
|
|
|
|
Sure thing ... first post your question here[^] otherwise see here[^]
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
1. Your question is not clear - please reword.
2. If this really is a question about SQL then this is not the appropriate forum.
|
|
|
|