Slowness in Entity C# when saving image

Asked

Viewed 38 times

0

I’m slowing down the system I created in c# using Entity Framework. At the moment when I am saving a record of an attachment, I am compressing the file. Before I check if it is . jpg or . pdf (only extensions accepted by the system). The files I am attaching have a maximum of 1MB, and yet the system is slow... Appears as "Not responding" and after a certain time (20 seconds approximately), persists. Someone knows what can be?

I already checked the network (is normal) and the computer configuration is good.

Follow my method codes to save and compress the files.

private void btnSalvar_Click(object sender, EventArgs e)
    {
        if (ValidaForm())
        {
            FANEXOMOVIMENTACAO anex = new FANEXOMOVIMENTACAO
            {
                MovimentacaoID = movimentacao.MovimentacaoID,
                AnexoID = txtCodAnexo.Text,
                Descricao = txtDescricao.Text,
                Tipo = "COMUM",
                Nome = Path.GetFileNameWithoutExtension(txtArquivo.Text),
                Extensao = Path.GetExtension(txtArquivo.Text),
                Arquivo = (Path.GetExtension(txtArquivo.Text) == ".pdf" ? Global.EncriptPDF(txtArquivo.Text) : Global.EncriptFoto(txtArquivo.Text)),
                DataCadastro = DateTime.Now,
                UsuarioCadastro = FormPrincipal.getUsuarioAcesso().LoginUsr
            };

            using (controle = new ControleFAnexoMovimentacao())
            {
                controle.Create(anex);
                controle.SaveAll();
                Global.MsgSucesso("Registro salvo com sucesso.");
                salvo = true;
            }

            if (Global.NovoRegistro() == DialogResult.Yes)
                LimparCampos();
            else
                this.Close();
        }
    }

And this is to compress the files:

 public static byte[] EncriptFoto(string img)
    {
        byte[] bytesImagem = null;
        FileStream fstream = new FileStream(img, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fstream);
        bytesImagem = br.ReadBytes((int)fstream.Length);

        return CompressBytes(bytesImagem);
    }


public static byte[] EncriptPDF(string pdf)
    {
        byte[] arrayDeBytes;

        using (Stream stream = new FileStream(pdf, FileMode.Open))
        {
            arrayDeBytes = new byte[stream.Length + 1];
            stream.Read(arrayDeBytes, 0, arrayDeBytes.Length);
        }

        return CompressBytes(arrayDeBytes);
    }
  • Is it SQL-Server? If so, check the expansion log of the BD and Log files. Many expansion records can cause slow recording as well as, the writing of indexes. These may not be the main factor, but they may be some of them.

  • Can debug to see which part occurs the slowest?

  • This slowness is occurring on the customer. On my local machine it is not occurring. I’m going to try to insert a lot of attachments into the bank to see if I can replicate the environment... but I still don’t think this is the cause of the problem.

  • I think I figured out what the problem is... database overload. I looked at the reports generated by SQL itself and noticed that my compression method is not compressing, just converting into an array of bytes.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.