MKR1000 gets reset each time I switch a digital pin output

I have made my first IoT project using MKR1000.
My project calculates the time between two consecutive LOW on digital pin 1.
And send that duration to server.
My problem is in hardware of the project, if I manually switch between Gnd and 5V on breadboard, the project runs fine but If I use a DPDT push button to toggle the digital pin between HIGH and LOW each time I press the push button MKR1000 resets itself.

How does a power change on a digital pin activates Hardware reset?
what can I do to solve this?

Can you supply a schematic as its sounds like the switch is not wired correctly and causes a short on button presses.

I don't have a proper schematics.
But i can explain it to you.
I have connected one terminal of DPDT switch to Gnd and other to 3.3V.
And my digital pin is connected in the middle.
So when I push the button then MKR1000 gets a hardware reset.

A hand drawn schematic will work just fine.

But it sounds like the way you have it is causing a short which would certainly reset the board.

There are thousands of pictures of how to properly wire a switch to an Arduino on google.
I would suggest though that you start HERE

Thanks for quick response, I have made the similar connection but i haven't used any resistance in between.
Is it because of the resistance.